From: Jean-Marc Lasgouttes Date: Fri, 21 Mar 2014 11:24:47 +0000 (+0100) Subject: Do not store Languages objects in completion words lists X-Git-Tag: 2.1.1~90^2~10 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=a556652f6ee4082b6917c3ca247cb7f7278dab47;p=features.git Do not store Languages objects in completion words lists In the current code each paragraph contains a map, 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. --- diff --git a/src/LyX.cpp b/src/LyX.cpp index 41c69f7dae..b7848311b8 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -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" diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index ffcb5f2f4b..4d9b37c1f7 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -499,7 +499,7 @@ public: TextContainer text_; typedef set Words; - typedef map LangWordsMap; + typedef map 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); } } } diff --git a/src/Text.cpp b/src/Text.cpp index c4cac8892e..cdcc200255 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -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); } diff --git a/src/WordList.cpp b/src/WordList.cpp index 762e1b93c6..3a095afca2 100644 --- a/src/WordList.cpp +++ b/src/WordList.cpp @@ -12,14 +12,11 @@ #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 @@ -28,12 +25,13 @@ using namespace std; namespace lyx { /// -map theGlobalWordList; +typedef map GlobalWordList; +GlobalWordList theGlobalWordList; -WordList * theWordList(Language const & lang) +WordList * theWordList(string const & lang) { - map::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::const_iterator it = theGlobalWordList.begin(); + GlobalWordList::const_iterator it = theGlobalWordList.begin(); for (; it != theGlobalWordList.end(); ++it) delete it->second; theGlobalWordList.clear(); diff --git a/src/WordList.h b/src/WordList.h index b7f88fb78f..f57f20b068 100644 --- a/src/WordList.h +++ b/src/WordList.h @@ -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 diff --git a/status.21x b/status.21x index 4c647a95a4..1394ef4279 100644 --- a/status.21x +++ b/status.21x @@ -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