Re: par breaking
Edwin Leuven wrote: i've noticed that breaking a paragraph is much quicker than unbreaking it (cursor at beginning of par and then backspace) i think that this has always been the case, but i was wondering whether there is something that can be done about it? (i guess i am looking at you abdel ;-) This is fixed now! Abdel. Author: younes Date: Sat Jan 13 10:31:47 2007 New Revision: 16662 URL: http://www.lyx.org/trac/changeset/16662 Log: Messages: - cache_: new cache for gettext translated string. Modified: lyx-devel/trunk/src/messages.C lyx-devel/trunk/src/messages.h Modified: lyx-devel/trunk/src/messages.C URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/messages.C?rev=16662 == --- lyx-devel/trunk/src/messages.C (original) +++ lyx-devel/trunk/src/messages.C Sat Jan 13 10:31:47 2007 @@ -21,16 +21,16 @@ #include boost/regex.hpp #include cerrno - +#include map + +using std::endl; +using std::string; namespace lyx { using support::package; using support::getEnv; using support::setEnv; - -using std::string; -using std::endl; static boost::regex const reg(^([^\\[]*)\\[\\[[^\\]]*\\]\\]$); @@ -114,10 +114,17 @@ ~Pimpl() {} - docstring const get(string const m) const - { + docstring const get(string const m) const + { + static docstring empty_string; if (m.empty()) - return from_ascii(m); + return empty_string; + + // Look for the translated string in the cache. + CacheType::iterator it = cache_.find(m); + if (it != cache_.end()) + return it-second; + // The string was not found, use gettext to generate it: // In this order, see support/filetools.C: string lang = getEnv(LC_ALL); @@ -206,11 +213,18 @@ setlocale(LC_MESSAGES, lang.c_str()); #endif setlocale(LC_CTYPE, oldCTYPE.c_str()); - return translated; + + it = cache_.insert(std::make_pair(m, translated)).first; + return it-second; } private: /// string lang_; + typedef std::mapstring, docstring CacheType; + /// Internal cache for gettext translated strings. + /// This is needed for performance reason within \c updateLabels() + /// under Windows. + mutable CacheType cache_; }; #endif @@ -250,7 +264,7 @@ {} -docstring const Messages::get(string const msg) const +docstring const Messages::get(string const msg) const { return pimpl_-get(msg); } Modified: lyx-devel/trunk/src/messages.h URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/messages.h?rev=16662 == --- lyx-devel/trunk/src/messages.h (original) +++ lyx-devel/trunk/src/messages.h Sat Jan 13 10:31:47 2007 @@ -29,7 +29,7 @@ /// ~Messages(); /// - docstring const get(std::string const msg) const; + docstring const get(std::string const msg) const; private: class Pimpl; boost::scoped_ptrPimpl pimpl_;
Re: par breaking
Abdelrazak Younes [EMAIL PROTECTED] writes: | private: | /// | string lang_; | + typedef std::mapstring, docstring CacheType; | + /// Internal cache for gettext translated strings. | + /// This is needed for performance reason within \c updateLabels() | + /// under Windows. | + mutable CacheType cache_; | }; I think the CacheType should be given a better name. Just to describe loosely what kind of a cache it is. -- Lgb
Re: par breaking
Lars Gullik Bjønnes wrote: Abdelrazak Younes [EMAIL PROTECTED] writes: | private: | /// | string lang_; | + typedef std::mapstring, docstring CacheType; | + /// Internal cache for gettext translated strings. | + /// This is needed for performance reason within \c updateLabels() | + /// under Windows. | + mutable CacheType cache_; | }; I think the CacheType should be given a better name. Just to describe loosely what kind of a cache it is. I've done that. Abdel.
Re: par breaking
Edwin Leuven wrote: i've noticed that breaking a paragraph is much quicker than "unbreaking" it (cursor at beginning of par and then backspace) i think that this has always been the case, but i was wondering whether there is something that can be done about it? (i guess i am looking at you abdel ;-) This is fixed now! Abdel. Author: younes Date: Sat Jan 13 10:31:47 2007 New Revision: 16662 URL: http://www.lyx.org/trac/changeset/16662 Log: Messages: - cache_: new cache for gettext translated string. Modified: lyx-devel/trunk/src/messages.C lyx-devel/trunk/src/messages.h Modified: lyx-devel/trunk/src/messages.C URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/messages.C?rev=16662 == --- lyx-devel/trunk/src/messages.C (original) +++ lyx-devel/trunk/src/messages.C Sat Jan 13 10:31:47 2007 @@ -21,16 +21,16 @@ #include #include - +#include + +using std::endl; +using std::string; namespace lyx { using support::package; using support::getEnv; using support::setEnv; - -using std::string; -using std::endl; static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$"); @@ -114,10 +114,17 @@ ~Pimpl() {} - docstring const get(string const & m) const - { + docstring const & get(string const & m) const + { + static docstring empty_string; if (m.empty()) - return from_ascii(m); + return empty_string; + + // Look for the translated string in the cache. + CacheType::iterator it = cache_.find(m); + if (it != cache_.end()) + return it->second; + // The string was not found, use gettext to generate it: // In this order, see support/filetools.C: string lang = getEnv("LC_ALL"); @@ -206,11 +213,18 @@ setlocale(LC_MESSAGES, lang.c_str()); #endif setlocale(LC_CTYPE, oldCTYPE.c_str()); - return translated; + + it = cache_.insert(std::make_pair(m, translated)).first; + return it->second; } private: /// string lang_; + typedef std::mapCacheType; + /// Internal cache for gettext translated strings. + /// This is needed for performance reason within \c updateLabels() + /// under Windows. + mutable CacheType cache_; }; #endif @@ -250,7 +264,7 @@ {} -docstring const Messages::get(string const & msg) const +docstring const & Messages::get(string const & msg) const { return pimpl_->get(msg); } Modified: lyx-devel/trunk/src/messages.h URL: http://www.lyx.org/trac/file/lyx-devel/trunk/src/messages.h?rev=16662 == --- lyx-devel/trunk/src/messages.h (original) +++ lyx-devel/trunk/src/messages.h Sat Jan 13 10:31:47 2007 @@ -29,7 +29,7 @@ /// ~Messages(); /// - docstring const get(std::string const & msg) const; + docstring const & get(std::string const & msg) const; private: class Pimpl; boost::scoped_ptr pimpl_;
Re: par breaking
Abdelrazak Younes <[EMAIL PROTECTED]> writes: | private: | /// | string lang_; | + typedef std::mapCacheType; | + /// Internal cache for gettext translated strings. | + /// This is needed for performance reason within \c updateLabels() | + /// under Windows. | + mutable CacheType cache_; | }; I think the CacheType should be given a "better" name. Just to describe loosely what kind of a cache it is. -- Lgb
Re: par breaking
Lars Gullik Bjønnes wrote: Abdelrazak Younes <[EMAIL PROTECTED]> writes: | private: | /// | string lang_; | + typedef std::mapCacheType; | + /// Internal cache for gettext translated strings. | + /// This is needed for performance reason within \c updateLabels() | + /// under Windows. | + mutable CacheType cache_; | }; I think the CacheType should be given a "better" name. Just to describe loosely what kind of a cache it is. I've done that. Abdel.
par breaking
i've noticed that breaking a paragraph is much quicker than unbreaking it (cursor at beginning of par and then backspace) i think that this has always been the case, but i was wondering whether there is something that can be done about it? (i guess i am looking at you abdel ;-) and of course best wishes for 2007 to all of you!
Re: par breaking
Edwin Leuven wrote: i've noticed that breaking a paragraph is much quicker than unbreaking it (cursor at beginning of par and then backspace) i think that this has always been the case, Actually, breaking a paragraph has been optimized when within a non-numbered layout (look at the updateLabels() different calls). but i was wondering whether there is something that can be done about it? Sure, the same optimization can be done for unbreaking. Just replace the full updateLabels() with one of the localised one. (i guess i am looking at you abdel ;-) Don't look farther :-) Abdel.
par breaking
i've noticed that breaking a paragraph is much quicker than "unbreaking" it (cursor at beginning of par and then backspace) i think that this has always been the case, but i was wondering whether there is something that can be done about it? (i guess i am looking at you abdel ;-) and of course best wishes for 2007 to all of you!
Re: par breaking
Edwin Leuven wrote: i've noticed that breaking a paragraph is much quicker than "unbreaking" it (cursor at beginning of par and then backspace) i think that this has always been the case, Actually, breaking a paragraph has been optimized when within a non-numbered layout (look at the updateLabels() different calls). but i was wondering whether there is something that can be done about it? Sure, the same optimization can be done for "unbreaking". Just replace the full updateLabels() with one of the localised one. (i guess i am looking at you abdel ;-) Don't look farther :-) Abdel.