From a6980e1f41e145dbfecb56ef5dc0ed895d0cf893 Mon Sep 17 00:00:00 2001 From: cxl Date: Thu, 15 Oct 2015 21:55:40 +0000 Subject: [PATCH] ide: fixed issue with high memory consumption #1292 git-svn-id: svn://ultimatepp.org/upp/trunk@9022 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CodeEditor/CodeEditor.cpp | 11 +++++- uppsrc/CodeEditor/CodeEditor.h | 3 ++ uppsrc/CppBase/ppfile.cpp | 63 +++++++++++++++++++++++++++++++- uppsrc/ide/Assist.cpp | 2 + uppsrc/ide/Browser/Base.cpp | 11 +++++- 5 files changed, 85 insertions(+), 5 deletions(-) diff --git a/uppsrc/CodeEditor/CodeEditor.cpp b/uppsrc/CodeEditor/CodeEditor.cpp index aa9ef29fa..acead2b31 100644 --- a/uppsrc/CodeEditor/CodeEditor.cpp +++ b/uppsrc/CodeEditor/CodeEditor.cpp @@ -867,10 +867,16 @@ bool CodeEditor::Key(dword code, int count) { bool sel = code & K_SHIFT; switch(code & ~K_SHIFT) { case K_CTRL_F: - FindReplace(sel, true, false); + if(withfindreplace) { + FindReplace(sel, true, false); + return true; + } break; case K_CTRL_H: - FindReplace(sel, true, true); + if(withfindreplace) { + FindReplace(sel, true, true); + return true; + } break; case K_F3: if(sel) @@ -1053,6 +1059,7 @@ CodeEditor::CodeEditor() { check_edited = false; tippos = -1; selkind = SEL_CHARS; + withfindreplace = true; } CodeEditor::~CodeEditor() {} diff --git a/uppsrc/CodeEditor/CodeEditor.h b/uppsrc/CodeEditor/CodeEditor.h index 4f1d052a4..f9255ce9f 100644 --- a/uppsrc/CodeEditor/CodeEditor.h +++ b/uppsrc/CodeEditor/CodeEditor.h @@ -239,6 +239,7 @@ protected: bool check_edited; bool persistent_find_replace; bool do_ff_restore_pos; + bool withfindreplace; int ff_start_pos; @@ -459,6 +460,8 @@ public: void IndentSpaces(bool is) { indent_spaces = is; } void IndentAmount(int ia) { indent_amount = ia; } void NoParenthesisIndent(bool b) { no_parenthesis_indent = b; } + + void NoFindReplace() { withfindreplace = false; } void LineNumbers(bool b) { bar.LineNumbers(b); } void MarkLines(bool b) { mark_lines = b; } diff --git a/uppsrc/CppBase/ppfile.cpp b/uppsrc/CppBase/ppfile.cpp index 32ff386d5..47c58158d 100644 --- a/uppsrc/CppBase/ppfile.cpp +++ b/uppsrc/CppBase/ppfile.cpp @@ -83,9 +83,41 @@ static int sPPserial; void SweepPPFiles(const Index& keep) { + Index pp_segment_id; + int unlinked_count = 0; for(int i = 0; i < sPPfile.GetCount(); i++) - if(keep.Find(sPPfile.GetKey(i)) < 0 && !sPPfile.IsUnlinked(i)) - sPPfile.Unlink(i); + if(sPPfile.IsUnlinked(i)) + unlinked_count++; + else + if(keep.Find(sPPfile.GetKey(i)) < 0) { + unlinked_count++; + sPPfile.Unlink(i); + } + else { + RTIMING("Sweep2"); + const PPFile& p = sPPfile[i]; + for(int j = 0; j < p.item.GetCount(); j++) + pp_segment_id.FindAdd(p.item[j].segment_id); + } + if(unlinked_count > sPPfile.GetCount() / 2) { + CleanPP(); + return; + } + RTIMING("Sweep3"); + unlinked_count = 0; + for(int i = 0; i < sAllMacros.GetCount(); i++) { + if(sAllMacros.IsUnlinked(i)) + unlinked_count++; + else + if(pp_segment_id.Find(sAllMacros[i].segment_id) < 0) { + sAllMacros.Unlink(i); + unlinked_count++; + } + if(unlinked_count > sAllMacros.GetCount() / 2) { + CleanPP(); + return; + } + } } String GetSegmentFile(int segment_id) @@ -601,6 +633,33 @@ void SerializePPFiles(Stream& s) s % sAllMacros % sPPfile % sPPserial; if(s.IsLoading()) LoadPPConfig(); + +#if 0 + if(s.IsLoading()) { _DBG_ + DDUMP(sPPfile.GetCount()); + DDUMP(sAllMacros.GetCount()); + DDUMP(sPPserial); + + Index psegment; + for(int i = 0; i < sPPfile.GetCount(); i++) { + const PPFile& p = sPPfile[i]; + for(int j = 0; j < p.item.GetCount(); j++) + psegment.FindAdd(p.item[j].segment_id); + } + DDUMP(psegment.GetCount()); + + int n = 0; _DBG_ + Index msegment; + for(int i = 0; i < sAllMacros.GetCount(); i++) { _DBG_ + if(sAllMacros.IsUnlinked(i)) + n++; + else + msegment.FindAdd(sAllMacros[i].segment_id); + } + DLOG("UNLINKED " << n); + DLOG("Segments " << msegment.GetCount()); + } +#endif } END_UPP_NAMESPACE diff --git a/uppsrc/ide/Assist.cpp b/uppsrc/ide/Assist.cpp index c214acd27..7ff2afbb6 100644 --- a/uppsrc/ide/Assist.cpp +++ b/uppsrc/ide/Assist.cpp @@ -87,6 +87,8 @@ AssistEditor::AssistEditor() param_info.NoSb(); include_assist = false; + + NoFindReplace(); } int CppItemInfoOrder(const Value& va, const Value& vb) { diff --git a/uppsrc/ide/Browser/Base.cpp b/uppsrc/ide/Browser/Base.cpp index 66f3d0824..28bc56d5b 100644 --- a/uppsrc/ide/Browser/Base.cpp +++ b/uppsrc/ide/Browser/Base.cpp @@ -16,6 +16,8 @@ #define CLOG(x) #endif +#define MLOG(x) + #define CPP_CODEBASE_VERSION 314159 ArrayMap source_file; @@ -92,9 +94,13 @@ void BrowserScanError(int line, const String& text, int file) void SerializeCodeBase(Stream& s) { + MLOG(s.IsLoading()); source_file.Serialize(s); + MLOG("source_file " << MemoryUsedKb()); SerializePPFiles(s); + MLOG("PP files " << MemoryUsedKb()); CodeBase().Serialize(s); + MLOG("codebase " << MemoryUsedKb()); } void SaveCodeBase() @@ -111,7 +117,7 @@ void SaveCodeBase() bool TryLoadCodeBase(const char *pattern) { - CLOG("+++ Trying to load " << pattern); + LLOG("+++ Trying to load " << pattern); FindFile ff(pattern); String path; int64 len = -1; @@ -125,8 +131,10 @@ bool TryLoadCodeBase(const char *pattern) if(path.GetCount()) { LTIMING("Load code base"); StringStream ss(LZ4Decompress(LoadFile(path))); + MLOG("Decompressed " << MemoryUsedKb()); if(Load(callback(SerializeCodeBase), ss, CPP_CODEBASE_VERSION)) { CLOG("*** Loaded " << ff.GetPath() << ' ' << GetSysTime() << ", file count: " << source_file.GetCount() << ", codebase: " << CodeBase().GetCount()); + MLOG("TryLoadCodeBase loaded: " << MemoryUsedKb()); return true; } } @@ -135,6 +143,7 @@ bool TryLoadCodeBase(const char *pattern) void LoadCodeBase() { + MLOG("LoadCodeBase start: " << MemoryUsedKb()); TryLoadCodeBase(CodeBaseCacheFile()) || TryLoadCodeBase(AppendFileName(CodeBaseCacheDir(), GetVarsName() + ".*." + GetCurrentBuildMethod() + ".codebase")) || TryLoadCodeBase(AppendFileName(CodeBaseCacheDir(), GetVarsName() + ".*.codebase")) ||