]> git.lyx.org Git - features.git/commitdiff
Do not store Languages objects in completion words lists
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 21 Mar 2014 11:24:47 +0000 (12:24 +0100)
committerRichard Heck <rgheck@lyx.org>
Fri, 18 Apr 2014 14:52:48 +0000 (10:52 -0400)
In the current code each paragraph contains a map<Language,
WordList*>, which means that it contains a full copy of the language
object. Since these objects contain translation tables nowadays, this
is a very bad idea.

This patch simply replaces the Language key by a string.

When loading the Userguide on linux/x86_64, the total memory
consumption decreases from 36.27MB to 31.50MB.

src/LyX.cpp
src/Paragraph.cpp
src/Text.cpp
src/WordList.cpp
src/WordList.h
status.21x

index 41c69f7dae4d77f031290dfed4b0dede36b8de3d..b7848311b85a6a10450572285cab072a7bcf0f94 100644 (file)
@@ -33,6 +33,7 @@
 #include "FuncStatus.h"
 #include "HunspellChecker.h"
 #include "KeyMap.h"
+#include "Language.h"
 #include "LaTeXFonts.h"
 #include "LayoutFile.h"
 #include "Lexer.h"
index ffcb5f2f4bdeb8608875cace442b5faf2dbeeffd..4d9b37c1f73cbea209247e9273e64ad5654213b5 100644 (file)
@@ -499,7 +499,7 @@ public:
        TextContainer text_;
 
        typedef set<docstring> Words;
-       typedef map<Language, Words> LangWordsMap;
+       typedef map<string, Words> LangWordsMap;
        ///
        LangWordsMap words_;
        ///
@@ -3867,7 +3867,7 @@ void Paragraph::collectWords()
                        if (cit == d->fontlist_.end())
                                return;
                        Language const * lang = cit->font().language();
-                       d->words_[*lang].insert(word);
+                       d->words_[lang->lang()].insert(word);
                }
        }
 }
index c4cac8892ecd726c09a02d1a26e8db10c2d4615d..cdcc200255895912f6dec665d3a61716812bd59b 100644 (file)
@@ -2120,7 +2120,7 @@ bool Text::completionSupported(Cursor const & cur) const
 
 CompletionList const * Text::createCompletionList(Cursor const & cur) const
 {
-       WordList const * list = theWordList(*cur.getFont().language());
+       WordList const * list = theWordList(cur.getFont().language()->lang());
        return new TextCompletionList(cur, list);
 }
 
index 762e1b93c620411af87688dea91cbe0267eb2612..3a095afca230c3dba23bd0a93b9a3f14316f4671 100644 (file)
 
 #include "WordList.h"
 
-#include "Language.h"
-
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/docstring.h"
-#include "support/weighted_btree.h"
-
 #include "support/lassert.h"
+#include "support/weighted_btree.h"
 
 #include <map>
 
@@ -28,12 +25,13 @@ using namespace std;
 namespace lyx {
 
 ///
-map<Language, WordList *> theGlobalWordList;
+typedef map<string, WordList *> GlobalWordList;
+GlobalWordList theGlobalWordList;
 
 
-WordList * theWordList(Language const & lang)
+WordList * theWordList(string const & lang)
 {
-       map<Language, WordList *>::iterator it = theGlobalWordList.find(lang);
+       GlobalWordList::iterator it = theGlobalWordList.find(lang);
        if (it != theGlobalWordList.end())
                return it->second;
        else
@@ -44,7 +42,7 @@ WordList * theWordList(Language const & lang)
 
 void WordList::cleanupWordLists()
 {
-       map<Language, WordList *>::const_iterator it = theGlobalWordList.begin();
+       GlobalWordList::const_iterator it = theGlobalWordList.begin();
        for (; it != theGlobalWordList.end(); ++it)
                delete it->second;
        theGlobalWordList.clear();
index b7f88fb78f305767c278ec1fe19e1493b87de80b..f57f20b0680b278afda11463460c34578a69c3bf 100644 (file)
@@ -14,8 +14,6 @@
 
 #include "support/docstring.h"
 
-#include "Language.h"
-
 namespace lyx {
 
 class WordList {
@@ -41,7 +39,7 @@ private:
        Impl * d;
 };
 
-WordList * theWordList(Language const & lang);
+WordList * theWordList(std::string const & lang);
 
 } // namespace lyx
 
index 4c647a95a40ba149206deae32bdaeb06f0ef2ca0..1394ef4279e76f642839ebb1373c88d336dd190b 100644 (file)
@@ -83,6 +83,7 @@ What's new
 
 - Fix a problem when PATH changes and python command is relative (bug 8950).
 
+- Reduce memory use with large documents.
  
 
 * DOCUMENTATION AND LOCALIZATION