Maybe this helps against the crashes, it then there will be a copy again: Abdelrazak Younes wrote: > Abdelrazak Younes wrote: >> Could someone please test this under Linux? >> >> Enrico, if you could test it under Cygwin as well, that would be great. > > Take this patch if you want to see some debug outputs. It's working > perfectly here and it's really a _huge_ performance boost under Windows! > > Abdel. > > > ------------------------------------------------------------------------ > > Index: messages.C > =================================================================== > --- messages.C (revision 16645) > +++ messages.C (working copy) > @@ -21,7 +21,10 @@ > #include <boost/regex.hpp> > > #include <cerrno> > +#include <map> > > +using std::endl; > +using std::string; > > namespace lyx { > > @@ -29,10 +32,7 @@ > using support::getEnv; > using support::setEnv; > > -using std::string; > -using std::endl; > > - > static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$"); > > > @@ -114,11 +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; > > + CacheType::iterator it = cache_.find(m); > + if (it != cache_.end()) { > + lyxerr << "Cached translation " << to_utf8(it->second) > << endl;
empty_string = it->second; return empty_string; instead of 'return it->second;' because how long does it->second; live? > + return it->second; > + } > // In this order, see support/filetools.C: > string lang = getEnv("LC_ALL"); > if (lang.empty()) { > @@ -206,11 +212,16 @@ > setlocale(LC_MESSAGES, lang.c_str()); > #endif > setlocale(LC_CTYPE, oldCTYPE.c_str()); > - return translated; > + > + lyxerr << "New translation " << to_utf8(translated) << endl; > + it = cache_.insert(std::make_pair(m, translated)).first; same here: empty_string = it->second; return empty_string; > + return it->second; > } > private: > /// > string lang_; > + typedef std::map<string, docstring> CacheType; > + mutable CacheType cache_; > }; > #endif > > @@ -250,7 +261,7 @@ > {} > > > -docstring const Messages::get(string const & msg) const > +docstring const & Messages::get(string const & msg) const > { static empty_string = pimpl->get(msg); return empty_string; > return pimpl_->get(msg); > } > Index: messages.h > =================================================================== > --- messages.h (revision 16645) > +++ messages.h (working copy) > @@ -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> pimpl_; -- Peter Kümmel