]> git.lyx.org Git - lyx.git/commitdiff
Messages:
authorAbdelrazak Younes <younes@lyx.org>
Sat, 13 Jan 2007 09:31:47 +0000 (09:31 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 13 Jan 2007 09:31:47 +0000 (09:31 +0000)
- cache_: new cache for gettext translated string.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16662 a592a061-630c-0410-9148-cb99ea01b6c8

src/messages.C
src/messages.h

index 90a345470cbaaac57c0cb2aa09bbb14cdfa914c7..13098b87301d059f0d977b63d693b051a848f873 100644 (file)
 #include <boost/regex.hpp>
 
 #include <cerrno>
+#include <map>
 
+using std::endl;
+using std::string;
 
 namespace lyx {
 
@@ -29,9 +32,6 @@ using support::package;
 using support::getEnv;
 using support::setEnv;
 
-using std::string;
-using std::endl;
-
 
 static boost::regex const reg("^([^\\[]*)\\[\\[[^\\]]*\\]\\]$");
 
@@ -114,10 +114,17 @@ public:
 
        ~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 @@ public:
                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::map<string, 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 @@ Messages::~Messages()
 {}
 
 
-docstring const Messages::get(string const & msg) const
+docstring const Messages::get(string const & msg) const
 {
        return pimpl_->get(msg);
 }
index 39c7246ecddf5f2fc3f527644ce0ca94447742d5..8b211eaabed631e5606ccc98d617e5a151eccc4d 100644 (file)
@@ -29,7 +29,7 @@ public:
        ///
        ~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_;