Re: r35369 - lyx-devel/trunk/src
On 16/09/2010 17:31, Stephan Witt wrote: Am 14.09.2010 um 15:46 schrieb Abdelrazak Younes: On 09/14/2010 02:48 PM, sw...@lyx.org wrote: Author: switt Date: Tue Sep 14 14:48:03 2010 New Revision: 35369 URL: http://www.lyx.org/trac/changeset/35369 Log: reduce nesting levels in markMisspelledWords; simplify range check of fontspan I have a compile error: /home/younes/devel/lyx/trunk/src/Paragraph.cpp: In member function ‘void lyx::Paragraph::Private::markMisspelledWords(const lyx::pos_type, const lyx::pos_type, lyx::SpellChecker::Result, const lyx::docstring, const std::vectorlong int, std::allocatorlong int )’: /home/younes/devel/lyx/trunk/src/Paragraph.cpp:3538: error: no matching function for call to ‘lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int, __gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int, int)’ /home/younes/devel/lyx/trunk/src/Paragraph.cpp:366: note: candidates are: int lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int, __gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int, lyx::pos_type) const make[2]: *** [src/CMakeFiles/lyx2.0.dir/home/younes/devel/lyx/trunk/src/Paragraph.cpp.o] Error 1 Abdel. Of course the function Paragraph::Private::countSoftbreaks() should have int argument, but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? What's your environment? Kubuntu 10.04, gcc-4.3 I believe. Another question: I want to replace the map of the speller state by a vector to make it more similar to the FontList. The patch is attached. Is it ok? Sorry, no time but it seems to remove code so, if that doesn't introduce regression in performance this has to be good. Abdel.
Re: r35369 - lyx-devel/trunk/src
On 16/09/2010 17:31, Stephan Witt wrote: Am 14.09.2010 um 15:46 schrieb Abdelrazak Younes: On 09/14/2010 02:48 PM, sw...@lyx.org wrote: Author: switt Date: Tue Sep 14 14:48:03 2010 New Revision: 35369 URL: http://www.lyx.org/trac/changeset/35369 Log: reduce nesting levels in markMisspelledWords; simplify range check of fontspan I have a compile error: /home/younes/devel/lyx/trunk/src/Paragraph.cpp: In member function ‘void lyx::Paragraph::Private::markMisspelledWords(const lyx::pos_type&, const lyx::pos_type&, lyx::SpellChecker::Result, const lyx::docstring&, const std::vector >&)’: /home/younes/devel/lyx/trunk/src/Paragraph.cpp:3538: error: no matching function for call to ‘lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iterator > >&, __gnu_cxx::__normal_iterator > >&, int&)’ /home/younes/devel/lyx/trunk/src/Paragraph.cpp:366: note: candidates are: int lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iterator > >&, __gnu_cxx::__normal_iterator > >, lyx::pos_type&) const make[2]: *** [src/CMakeFiles/lyx2.0.dir/home/younes/devel/lyx/trunk/src/Paragraph.cpp.o] Error 1 Abdel. Of course the function Paragraph::Private::countSoftbreaks() should have int argument, but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? What's your environment? Kubuntu 10.04, gcc-4.3 I believe. Another question: I want to replace the map of the speller state by a vector to make it more similar to the FontList. The patch is attached. Is it ok? Sorry, no time but it seems to remove code so, if that doesn't introduce regression in performance this has to be good. Abdel.
Re: r35369 - lyx-devel/trunk/src
Am 14.09.2010 um 15:46 schrieb Abdelrazak Younes: On 09/14/2010 02:48 PM, sw...@lyx.org wrote: Author: switt Date: Tue Sep 14 14:48:03 2010 New Revision: 35369 URL: http://www.lyx.org/trac/changeset/35369 Log: reduce nesting levels in markMisspelledWords; simplify range check of fontspan I have a compile error: /home/younes/devel/lyx/trunk/src/Paragraph.cpp: In member function ‘void lyx::Paragraph::Private::markMisspelledWords(const lyx::pos_type, const lyx::pos_type, lyx::SpellChecker::Result, const lyx::docstring, const std::vectorlong int, std::allocatorlong int )’: /home/younes/devel/lyx/trunk/src/Paragraph.cpp:3538: error: no matching function for call to ‘lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int , __gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int , int)’ /home/younes/devel/lyx/trunk/src/Paragraph.cpp:366: note: candidates are: int lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int , __gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int , lyx::pos_type) const make[2]: *** [src/CMakeFiles/lyx2.0.dir/home/younes/devel/lyx/trunk/src/Paragraph.cpp.o] Error 1 Abdel. Of course the function Paragraph::Private::countSoftbreaks() should have int argument, but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? What's your environment? Another question: I want to replace the map of the speller state by a vector to make it more similar to the FontList. The patch is attached. Is it ok? Stephan Index: src/Paragraph.cpp === --- src/Paragraph.cpp (Revision 35413) +++ src/Paragraph.cpp (Arbeitskopie) @@ -73,9 +73,54 @@ char_type const META_INSET = 0x21; }; - / // +// SpellResultRange +// +/ +class SpellResultRange { +public: + SpellResultRange(FontSpan range, SpellChecker::Result result) + : range_(range), result_(result) + {} + /// + FontSpan range() const { return range_; } + /// + void range(FontSpan r) { range_ = r; } + /// + SpellChecker::Result result() const { return result_; } + /// + void result(SpellChecker::Result r) { result_ = r; } + /// + bool inside(pos_type pos) const { return range_.inside(pos); } + /// + bool covered(FontSpan r) const + { + // 1. first of new range inside current range or + // 2. last of new range inside current range or + // 3. first of current range inside new range or + // 4. last of current range inside new range + return range_.inside(r.first) || range_.inside(r.last) || + r.inside(range_.first) || r.inside(range_.last); + } + /// + void shift(pos_type pos, int offset) + { + if (range_.first pos) { + range_.first += offset; + range_.last += offset; + } else if (range_.last pos) { + range_.last += offset; + } + } +private: + FontSpan range_ ; + SpellChecker::Result result_ ; +}; + + +/ +// // SpellCheckerState // / @@ -91,7 +136,7 @@ { eraseCoveredRanges(fp); if (state != SpellChecker::WORD_OK) - ranges_[fp] = state; + ranges_.push_back(SpellResultRange(fp, state)); } void increasePosAfterPos(pos_type pos) @@ -112,10 +157,8 @@ RangesIterator et = ranges_.end(); RangesIterator it = ranges_.begin(); for (; it != et; ++it) { - FontSpan fc = it-first; - if(fc.first = pos pos = fc.last) { - result = it-second; - break; + if(it-inside(pos)) { + return it-result(); } } return result; @@ -155,52 +198,35 @@ } private: - /// store the ranges as map of FontSpan and spell result pairs - typedef mapFontSpan, SpellChecker::Result Ranges; + typedef vectorSpellResultRange Ranges; typedef Ranges::const_iterator RangesIterator; Ranges ranges_; - /// + /// the area of the paragraph with pending spell check FontSpan refresh_; bool needs_refresh_; +
Re: r35369 - lyx-devel/trunk/src
On 09/16/2010 11:31 AM, Stephan Witt wrote: Of course the function Paragraph::Private::countSoftbreaks() should have int argument, but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? Implicit conversion? rh
Re: r35369 - lyx-devel/trunk/src
Am 16.09.2010 um 17:47 schrieb Richard Heck: On 09/16/2010 11:31 AM, Stephan Witt wrote: Of course the function Paragraph::Private::countSoftbreaks() should have int argument, but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? Implicit conversion? Ok, bad question. The real question is, why had Abdel no implicit conversion on his box? Or here (pos_type == int) is true and not on Abdels box? Stephan
Re: r35369 - lyx-devel/trunk/src
Am 16.09.2010 um 17:47 schrieb Richard Heck: On 09/16/2010 11:31 AM, Stephan Witt wrote: Of course the function Paragraph::Private::countSoftbreaks() should have int argument, but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? Implicit conversion? Ok, bad question. (Sorry, I meant my original question.) The real question is, why had Abdel no implicit conversion on his box? Or here (pos_type == int) is true and not on Abdels box? Stephan
Re: r35369 - lyx-devel/trunk/src
On 09/16/2010 12:00 PM, Stephan Witt wrote: Am 16.09.2010 um 17:47 schrieb Richard Heck: On 09/16/2010 11:31 AM, Stephan Witt wrote: Of course the function Paragraph::Private::countSoftbreaks() should have int argument, but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? Implicit conversion? Ok, bad question. The real question is, why had Abdel no implicit conversion on his box? Or here (pos_type == int) is true and not on Abdels box? In LyX: typedef ptrdiff_t pos_type; In gcc: #ifndef __PTRDIFF_TYPE__ #define __PTRDIFF_TYPE__ long int #endif typedef __PTRDIFF_TYPE__ ptrdiff_t; Who knows for Abdel. rh Stephan
Re: r35369 - lyx-devel/trunk/src
Am 14.09.2010 um 15:46 schrieb Abdelrazak Younes: > On 09/14/2010 02:48 PM, sw...@lyx.org wrote: >> Author: switt >> Date: Tue Sep 14 14:48:03 2010 >> New Revision: 35369 >> URL: >> http://www.lyx.org/trac/changeset/35369 >> >> >> Log: >> reduce nesting levels in markMisspelledWords; simplify range check of >> fontspan > > I have a compile error: > > /home/younes/devel/lyx/trunk/src/Paragraph.cpp: In member function ‘void > lyx::Paragraph::Private::markMisspelledWords(const lyx::pos_type&, const > lyx::pos_type&, lyx::SpellChecker::Result, const lyx::docstring&, const > std::vector >&)’: > /home/younes/devel/lyx/trunk/src/Paragraph.cpp:3538: error: no matching > function for call to > ‘lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iterator long int*, std::vector > >&, > __gnu_cxx::__normal_iterator std::allocator > >&, int&)’ > /home/younes/devel/lyx/trunk/src/Paragraph.cpp:366: note: candidates are: int > lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iterator long int*, std::vector > >&, > __gnu_cxx::__normal_iterator std::allocator > >, lyx::pos_type&) const > make[2]: *** > [src/CMakeFiles/lyx2.0.dir/home/younes/devel/lyx/trunk/src/Paragraph.cpp.o] > Error 1 > > Abdel. Of course the function Paragraph::Private::countSoftbreaks() should have int argument, but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? What's your environment? Another question: I want to replace the map of the speller state by a vector to make it more similar to the FontList. The patch is attached. Is it ok? Stephan Index: src/Paragraph.cpp === --- src/Paragraph.cpp (Revision 35413) +++ src/Paragraph.cpp (Arbeitskopie) @@ -73,9 +73,54 @@ char_type const META_INSET = 0x21; }; - / // +// SpellResultRange +// +/ +class SpellResultRange { +public: + SpellResultRange(FontSpan range, SpellChecker::Result result) + : range_(range), result_(result) + {} + /// + FontSpan range() const { return range_; } + /// + void range(FontSpan r) { range_ = r; } + /// + SpellChecker::Result result() const { return result_; } + /// + void result(SpellChecker::Result r) { result_ = r; } + /// + bool inside(pos_type pos) const { return range_.inside(pos); } + /// + bool covered(FontSpan r) const + { + // 1. first of new range inside current range or + // 2. last of new range inside current range or + // 3. first of current range inside new range or + // 4. last of current range inside new range + return range_.inside(r.first) || range_.inside(r.last) || + r.inside(range_.first) || r.inside(range_.last); + } + /// + void shift(pos_type pos, int offset) + { + if (range_.first > pos) { + range_.first += offset; + range_.last += offset; + } else if (range_.last > pos) { + range_.last += offset; + } + } +private: + FontSpan range_ ; + SpellChecker::Result result_ ; +}; + + +/ +// // SpellCheckerState // / @@ -91,7 +136,7 @@ { eraseCoveredRanges(fp); if (state != SpellChecker::WORD_OK) - ranges_[fp] = state; + ranges_.push_back(SpellResultRange(fp, state)); } void increasePosAfterPos(pos_type pos) @@ -112,10 +157,8 @@ RangesIterator et = ranges_.end(); RangesIterator it = ranges_.begin(); for (; it != et; ++it) { - FontSpan fc = it->first; - if(fc.first <= pos && pos <= fc.last) { - result = it->second; - break; + if(it->inside(pos)) { + return it->result(); } } return result; @@ -155,52 +198,35 @@ } private: - /// store the ranges as map of FontSpan and spell result pairs - typedef mapRanges; + typedef vector Ranges; typedef Ranges::const_iterator RangesIterator; Ranges ranges_; - /// + /// the area of the paragraph with pending spell check FontSpan refresh_; bool needs_refresh_; + /// spell state cache version number SpellChecker::ChangeNumber current_change_number_; + void eraseCoveredRanges(FontSpan
Re: r35369 - lyx-devel/trunk/src
On 09/16/2010 11:31 AM, Stephan Witt wrote: Of course the function Paragraph::Private::countSoftbreaks() should have int argument, but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? Implicit conversion? rh
Re: r35369 - lyx-devel/trunk/src
Am 16.09.2010 um 17:47 schrieb Richard Heck: > On 09/16/2010 11:31 AM, Stephan Witt wrote: >> >> Of course the function Paragraph::Private::countSoftbreaks() should have int >> argument, >> but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? >> >> > Implicit conversion? Ok, bad question. The real question is, why had Abdel no implicit conversion on his box? Or here (pos_type == int) is true and not on Abdels box? Stephan
Re: r35369 - lyx-devel/trunk/src
Am 16.09.2010 um 17:47 schrieb Richard Heck: > On 09/16/2010 11:31 AM, Stephan Witt wrote: >> >> Of course the function Paragraph::Private::countSoftbreaks() should have int >> argument, >> but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? >> >> > Implicit conversion? Ok, bad question. (Sorry, I meant my original question.) The real question is, why had Abdel no implicit conversion on his box? Or here (pos_type == int) is true and not on Abdels box? Stephan
Re: r35369 - lyx-devel/trunk/src
On 09/16/2010 12:00 PM, Stephan Witt wrote: Am 16.09.2010 um 17:47 schrieb Richard Heck: On 09/16/2010 11:31 AM, Stephan Witt wrote: Of course the function Paragraph::Private::countSoftbreaks() should have int argument, but why did it compile here with gcc 4.2.1 on Mac and gcc 4.4 on Linux? Implicit conversion? Ok, bad question. The real question is, why had Abdel no implicit conversion on his box? Or here (pos_type == int) is true and not on Abdels box? In LyX: typedef ptrdiff_t pos_type; In gcc: #ifndef __PTRDIFF_TYPE__ #define __PTRDIFF_TYPE__ long int #endif typedef __PTRDIFF_TYPE__ ptrdiff_t; Who knows for Abdel. rh Stephan
Re: r35369 - lyx-devel/trunk/src
On 09/14/2010 02:48 PM, sw...@lyx.org wrote: Author: switt Date: Tue Sep 14 14:48:03 2010 New Revision: 35369 URL: http://www.lyx.org/trac/changeset/35369 Log: reduce nesting levels in markMisspelledWords; simplify range check of fontspan I have a compile error: /home/younes/devel/lyx/trunk/src/Paragraph.cpp: In member function ‘void lyx::Paragraph::Private::markMisspelledWords(const lyx::pos_type, const lyx::pos_type, lyx::SpellChecker::Result, const lyx::docstring, const std::vectorlong int, std::allocatorlong int )’: /home/younes/devel/lyx/trunk/src/Paragraph.cpp:3538: error: no matching function for call to ‘lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int , __gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int , int)’ /home/younes/devel/lyx/trunk/src/Paragraph.cpp:366: note: candidates are: int lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int , __gnu_cxx::__normal_iteratorconst long int*, std::vectorlong int, std::allocatorlong int , lyx::pos_type) const make[2]: *** [src/CMakeFiles/lyx2.0.dir/home/younes/devel/lyx/trunk/src/Paragraph.cpp.o] Error 1 Abdel. Modified: lyx-devel/trunk/src/Paragraph.cpp lyx-devel/trunk/src/Paragraph.h Modified: lyx-devel/trunk/src/Paragraph.cpp == --- lyx-devel/trunk/src/Paragraph.cpp Tue Sep 14 14:39:33 2010(r35368) +++ lyx-devel/trunk/src/Paragraph.cpp Tue Sep 14 14:48:03 2010(r35369) @@ -174,11 +174,9 @@ // 1. first of new range inside current range or // 2. last of new range inside current range or // 3. first of current range inside new range or - // 4. last of current range inside new range or - if ((fc.first= fp.first fp.first= fc.last) || - (fc.first= fp.last fp.last= fc.last) || - (fp.first= fc.first fc.first= fp.last) || - (fp.first= fc.last fc.last= fp.last)) + // 4. last of current range inside new range + if (fc.inside(fp.first) || fc.inside(fp.last) || + fp.inside(fc.first) || fp.inside(fc.last)) { continue; } @@ -364,7 +362,18 @@ } last = endpos; } - + + int countSoftbreaks(PositionsIterator it, PositionsIterator const et, pos_type start) const + { + int numbreaks = 0; + while (it != et *it start) { + ++start; + ++numbreaks; + ++it; + } + return numbreaks; + } + void markMisspelledWords(pos_type const first, pos_type const last, SpellChecker::Result result, docstring const word, @@ -3505,45 +3514,42 @@ docstring const word, Positions const softbreaks) { + if (!SpellChecker::misspelled(result)) { + setMisspelled(first, last, SpellChecker::WORD_OK); + return; + } pos_type snext = first; - if (SpellChecker::misspelled(result)) { - SpellChecker * speller = theSpellChecker(); - // locate and enumerate the error positions - int nerrors = speller-numMisspelledWords(); - int numbreaks = 0; - PositionsIterator it = softbreaks.begin(); - PositionsIterator et = softbreaks.end(); - for (int index = 0; index nerrors; ++index) { - int wstart; - int wlen = 0; - speller-misspelledWord(index, wstart, wlen); - if (wlen) { - docstring const misspelled = word.substr(wstart, wlen); - wstart += first + numbreaks; - if (snext wstart) { - while (it != et *it wstart) { - ++wstart; - ++numbreaks; - ++it; - } - setMisspelled(snext, - wstart - 1, SpellChecker::WORD_OK); - } - snext = wstart + wlen; - while (it != et *it snext) { -
Re: r35369 - lyx-devel/trunk/src
On 09/14/2010 02:48 PM, sw...@lyx.org wrote: Author: switt Date: Tue Sep 14 14:48:03 2010 New Revision: 35369 URL: http://www.lyx.org/trac/changeset/35369 Log: reduce nesting levels in markMisspelledWords; simplify range check of fontspan I have a compile error: /home/younes/devel/lyx/trunk/src/Paragraph.cpp: In member function ‘void lyx::Paragraph::Private::markMisspelledWords(const lyx::pos_type&, const lyx::pos_type&, lyx::SpellChecker::Result, const lyx::docstring&, const std::vector >&)’: /home/younes/devel/lyx/trunk/src/Paragraph.cpp:3538: error: no matching function for call to ‘lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iteratorlong int*, std::vector > >&, __gnu_cxx::__normal_iteratorstd::allocator > >&, int&)’ /home/younes/devel/lyx/trunk/src/Paragraph.cpp:366: note: candidates are: int lyx::Paragraph::Private::countSoftbreaks(__gnu_cxx::__normal_iteratorlong int*, std::vector > >&, __gnu_cxx::__normal_iteratorstd::allocator > >, lyx::pos_type&) const make[2]: *** [src/CMakeFiles/lyx2.0.dir/home/younes/devel/lyx/trunk/src/Paragraph.cpp.o] Error 1 Abdel. Modified: lyx-devel/trunk/src/Paragraph.cpp lyx-devel/trunk/src/Paragraph.h Modified: lyx-devel/trunk/src/Paragraph.cpp == --- lyx-devel/trunk/src/Paragraph.cpp Tue Sep 14 14:39:33 2010(r35368) +++ lyx-devel/trunk/src/Paragraph.cpp Tue Sep 14 14:48:03 2010(r35369) @@ -174,11 +174,9 @@ // 1. first of new range inside current range or // 2. last of new range inside current range or // 3. first of current range inside new range or - // 4. last of current range inside new range or - if ((fc.first<= fp.first&& fp.first<= fc.last) || - (fc.first<= fp.last&& fp.last<= fc.last) || - (fp.first<= fc.first&& fc.first<= fp.last) || - (fp.first<= fc.last&& fc.last<= fp.last)) + // 4. last of current range inside new range + if (fc.inside(fp.first) || fc.inside(fp.last) || + fp.inside(fc.first) || fp.inside(fc.last)) { continue; } @@ -364,7 +362,18 @@ } last = endpos; } - + + int countSoftbreaks(PositionsIterator& it, PositionsIterator const et, pos_type& start) const + { + int numbreaks = 0; + while (it != et&& *it< start) { + ++start; + ++numbreaks; + ++it; + } + return numbreaks; + } + void markMisspelledWords(pos_type const& first, pos_type const& last, SpellChecker::Result result, docstring const& word, @@ -3505,45 +3514,42 @@ docstring const& word, Positions const& softbreaks) { + if (!SpellChecker::misspelled(result)) { + setMisspelled(first, last, SpellChecker::WORD_OK); + return; + } pos_type snext = first; - if (SpellChecker::misspelled(result)) { - SpellChecker * speller = theSpellChecker(); - // locate and enumerate the error positions - int nerrors = speller->numMisspelledWords(); - int numbreaks = 0; - PositionsIterator it = softbreaks.begin(); - PositionsIterator et = softbreaks.end(); - for (int index = 0; index< nerrors; ++index) { - int wstart; - int wlen = 0; - speller->misspelledWord(index, wstart, wlen); - if (wlen) { - docstring const misspelled = word.substr(wstart, wlen); - wstart += first + numbreaks; - if (snext< wstart) { - while (it != et&& *it< wstart) { - ++wstart; - ++numbreaks; - ++it; - } - setMisspelled(snext, - wstart - 1, SpellChecker::WORD_OK); - } - snext = wstart + wlen; - while (it != et&& *it< snext) { - ++snext; - ++numbreaks; - ++it; -