From ad921e4852cf18b5469e39587e14b9f4aa081aa5 Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 6 Oct 2013 15:54:11 +0000 Subject: [PATCH] ide: Replace in block optimized, Highlighting thousands git-svn-id: svn://ultimatepp.org/upp/trunk@6398 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CodeEditor/CodeEditor.cpp | 6 +++ uppsrc/CodeEditor/CodeEditor.h | 2 + uppsrc/CodeEditor/EditorBar.cpp | 1 + uppsrc/CodeEditor/FindReplace.cpp | 61 ++++++++++++++++++++----------- uppsrc/CodeEditor/Highlight.cpp | 12 ++++-- uppsrc/CodeEditor/hl_color.i | 2 + uppsrc/CtrlLib/Text.cpp | 4 ++ uppsrc/ide/Browser/TopicBase.cpp | 2 +- uppsrc/ide/Setup.cpp | 2 +- 9 files changed, 65 insertions(+), 27 deletions(-) diff --git a/uppsrc/CodeEditor/CodeEditor.cpp b/uppsrc/CodeEditor/CodeEditor.cpp index 0394bec44..25908f395 100644 --- a/uppsrc/CodeEditor/CodeEditor.cpp +++ b/uppsrc/CodeEditor/CodeEditor.cpp @@ -26,6 +26,7 @@ inline bool IsComment(int a, int b) { } void CodeEditor::PreInsert(int pos, const WString& text) { + DTIMING("PreInsert"); if(IsFullRefresh()) return; rm_ins = ScanSyntax(GetLine(pos) + 1); } @@ -45,6 +46,7 @@ void CodeEditor::CheckBraces(const WString& text) } void CodeEditor::PostInsert(int pos, const WString& text) { + DTIMING("PostInsert"); if(check_edited) bar.SetEdited(GetLine(pos)); if(IsFullRefresh()) return; @@ -63,6 +65,7 @@ void CodeEditor::PostInsert(int pos, const WString& text) { } void CodeEditor::PreRemove(int pos, int size) { + DTIMING("PreRemove"); if(IsFullRefresh()) return; if(size > 200) Refresh(); @@ -77,6 +80,7 @@ void CodeEditor::PreRemove(int pos, int size) { } void CodeEditor::PostRemove(int pos, int size) { + DTIMING("PostRemove"); if(check_edited) bar.SetEdited(GetLine(pos)); if(IsFullRefresh()) return; @@ -1002,7 +1006,9 @@ void CodeEditor::DefaultHlStyles() SetHlStyle(INK_CONST_STRINGOP, LtBlue); SetHlStyle(INK_CONST_INT, Red); + SetHlStyle(INK_CONST_INT_3, Red, true, false, false); SetHlStyle(INK_CONST_FLOAT, Magenta); + SetHlStyle(INK_CONST_FLOAT_3, Magenta, true, false, false); SetHlStyle(INK_CONST_HEX, Blue); SetHlStyle(INK_CONST_OCT, Blue); diff --git a/uppsrc/CodeEditor/CodeEditor.h b/uppsrc/CodeEditor/CodeEditor.h index 7e3274368..b1120ed88 100644 --- a/uppsrc/CodeEditor/CodeEditor.h +++ b/uppsrc/CodeEditor/CodeEditor.h @@ -314,6 +314,7 @@ protected: Array foundwild; bool foundsel; bool found, notfoundfw, notfoundbk; + int foundpos, foundsize; int iwc; @@ -434,6 +435,7 @@ public: void CloseFindReplace(); void FindReplace(bool pick_selection, bool pick_text, bool replace); + bool FindFrom(int pos, bool back, const wchar *text, bool wholeword, bool ignorecase, bool wildcards, bool block); bool Find(bool back, const wchar *text, bool wholeword, bool ignorecase, bool wildcards, bool block); bool Find(bool back = false, bool blockreplace = false, bool replace = false); diff --git a/uppsrc/CodeEditor/EditorBar.cpp b/uppsrc/CodeEditor/EditorBar.cpp index 79fb3d19a..b12f20af9 100644 --- a/uppsrc/CodeEditor/EditorBar.cpp +++ b/uppsrc/CodeEditor/EditorBar.cpp @@ -370,6 +370,7 @@ void EditorBar::SetBreakpoint(int ln, const String& s) void EditorBar::SetEdited(int ln, int count) { + DTIMING("SetEdited"); if(ignored_next_edit) { ignored_next_edit = false; return; diff --git a/uppsrc/CodeEditor/FindReplace.cpp b/uppsrc/CodeEditor/FindReplace.cpp index 486b4939e..b653bd8f0 100644 --- a/uppsrc/CodeEditor/FindReplace.cpp +++ b/uppsrc/CodeEditor/FindReplace.cpp @@ -127,8 +127,24 @@ int CodeEditor::Match(const wchar *f, const wchar *s, int line, bool we, bool ig } bool CodeEditor::Find(bool back, const wchar *text, bool wholeword, bool ignorecase, - bool wildcards, bool block) + bool wildcards, bool block) { + DTIMING("Find"); + if(notfoundfw) MoveTextBegin(); + if(notfoundbk) MoveTextEnd(); + int cursor, pos; + if(found) + GetSelection(pos, cursor); + else + GetSelection(cursor, pos); + pos = cursor; + return FindFrom(pos, back, text, wholeword, ignorecase, wildcards, block); +} + + +bool CodeEditor::FindFrom(int pos, bool back, const wchar *text, bool wholeword, bool ignorecase, + bool wildcards, bool block) { + DTIMING("Find2"); WString ft; const wchar *s = text; while(*s) { @@ -158,35 +174,32 @@ bool CodeEditor::Find(bool back, const wchar *text, bool wholeword, bool ignorec else ft.Cat(c); } - foundwild.Clear(); - if(ft.IsEmpty()) return false; - if(notfoundfw) MoveTextBegin(); - if(notfoundbk) MoveTextEnd(); bool wb = wholeword ? iscidl(*ft) : false; bool we = wholeword ? iscidl(*ft.Last()) : false; - int cursor, pos; - if(found) - GetSelection(pos, cursor); - else - GetSelection(cursor, pos); - pos = cursor; + if(ft.IsEmpty()) return false; + foundwild.Clear(); int line = GetLinePos(pos); int linecount = GetLineCount(); WString ln = GetWLine(line); const wchar *l = ln; s = l + pos; + DTIMING("Find3"); for(;;) { for(;;) { if(!wb || (s == l || !iscidl(s[-1]))) { int n = Match(ft, s, line, we, ignorecase); if(n >= 0) { + DTIMING("Find4"); int pos = GetPos(line, int(s - l)); if(!back || pos + n < cursor) { - foundsel = true; - SetSelection(pos, pos + n); - foundsel = false; - if(!block) + if(!block) { + foundsel = true; + SetSelection(pos, pos + n); + foundsel = false; CenterCursor(); + } + foundpos = pos; + foundsize = n; found = true; return true; } @@ -200,12 +213,14 @@ bool CodeEditor::Find(bool back, const wchar *text, bool wholeword, bool ignorec } if(back) { if(--line < 0) break; + DTIMING("Find5"); ln = GetWLine(line); l = ln; s = ln.End(); } else { if(++line >= linecount) break; + DTIMING("Find6"); ln = GetWLine(line); l = s = ln; } @@ -271,6 +286,7 @@ WString CodeEditor::GetReplaceText() WString CodeEditor::GetReplaceText(WString rs, bool wildcards, bool samecase) { + DTIMING("GetReplaceText"); int anyi = 0, onei = 0, spacei = 0, numberi = 0, idi = 0; WString rt; const wchar *s = rs; @@ -389,20 +405,21 @@ void CodeEditor::Replace() int CodeEditor::BlockReplace(WString find, WString replace, bool wholeword, bool ignorecase, bool wildcards, bool samecase) { NextUndo(); + Refresh(); // Setting full-refresh here avoids Pre/Post Remove/Insert costs int l, h; if(!GetSelection(l, h)) return 0; PlaceCaret(l); int count = 0; - for(;;) { - if(!Find(false, find, wholeword, ignorecase, wildcards, true) || cursor > h) break; - int hh, ll; - GetSelection(ll, hh); - CachePos(ll); - h = h - (hh - ll) + Paste(GetReplaceText(replace, wildcards, ignorecase && samecase)); + foundpos = l; + while(FindFrom(foundpos, false, find, wholeword, ignorecase, wildcards, true) && foundpos + foundsize <= h) { + CachePos(foundpos); + Remove(foundpos, foundsize); + WString rt = GetReplaceText(replace, wildcards, ignorecase && samecase); + Insert(foundpos, rt); + h = h - foundsize + rt.GetCount(); count++; } SetSelection(l, h); - Refresh(); return count; } diff --git a/uppsrc/CodeEditor/Highlight.cpp b/uppsrc/CodeEditor/Highlight.cpp index b1ff98f29..ccbe09e53 100644 --- a/uppsrc/CodeEditor/Highlight.cpp +++ b/uppsrc/CodeEditor/Highlight.cpp @@ -698,7 +698,8 @@ void CodeEditor::HighlightLine(int line, Vector& hl, int po int c = INK_CONST_INT; bool isDot, isFloat = false; if(*p == '0') c = INK_CONST_OCT; - while(IsDigit(*p)) p++; + while(IsDigit(*p)) p++; + int fixdigits = p - t; if(*p == '.' || (*p == 'e' || *p == 'E') && highlight != HIGHLIGHT_CSS) { if(*p == '.') isDot = true; @@ -714,8 +715,13 @@ void CodeEditor::HighlightLine(int line, Vector& hl, int po } if(c == INK_CONST_OCT && p - t == 1) c = INK_CONST_INT; - if(p - t > 0) - hls.Put(int(p - t), hl_style[c]); + int n = int(p - t); + for(int i = 0; i < n; i++) { + int q = fixdigits - i; + hls.Put(fixdigits > 4 && q > 0 && q % 3 == 0 && c != INK_CONST_OCT ? + hl_style[c == INK_CONST_INT ? INK_CONST_INT_3 : INK_CONST_FLOAT_3] + : hl_style[c]); + } } else if(pair == MAKELONG('t', '_') && p[2] == '(' && p[3] == '\"') { diff --git a/uppsrc/CodeEditor/hl_color.i b/uppsrc/CodeEditor/hl_color.i index aec59ff5f..1ec5a9d49 100644 --- a/uppsrc/CodeEditor/hl_color.i +++ b/uppsrc/CodeEditor/hl_color.i @@ -19,7 +19,9 @@ HL_COLOR(INK_PAR1, "Brackets level 2", 1) HL_COLOR(INK_PAR2, "Brackets level 3", 1) HL_COLOR(INK_PAR3, "Brackets level 4", 1) HL_COLOR(INK_CONST_INT, "Decimal constant", 1) +HL_COLOR(INK_CONST_INT_3, "Decimal constant thousands", 1) HL_COLOR(INK_CONST_FLOAT, "FP constant", 1) +HL_COLOR(INK_CONST_FLOAT_3, "FP constant thousands", 1) HL_COLOR(INK_CONST_HEX, "Hexadecimal constant", 1) HL_COLOR(INK_CONST_OCT, "Octal constant", 1) HL_COLOR(INK_CONST_STRINGOP, "Format field", 1) diff --git a/uppsrc/CtrlLib/Text.cpp b/uppsrc/CtrlLib/Text.cpp index 9f72132e3..adeb6dbaa 100644 --- a/uppsrc/CtrlLib/Text.cpp +++ b/uppsrc/CtrlLib/Text.cpp @@ -81,6 +81,7 @@ void TextCtrl::SetSb() {} void TextCtrl::PlaceCaret(int newcursor, bool sel) {} void TextCtrl::CachePos(int pos) { + DTIMING("CachePos"); int p = pos; cline = GetLinePos(p); cpos = pos - p; @@ -475,6 +476,7 @@ void TextCtrl::RemoveU(int pos, int size) { } int TextCtrl::Insert(int pos, const WString& _txt, bool typing) { + DTIMING("Insert"); WString txt = _txt; if(charset != CHARSET_UNICODE && charset != CHARSET_UTF8_BOM) for(int i = 0; i < txt.GetCount(); i++) @@ -491,6 +493,7 @@ int TextCtrl::Insert(int pos, const String& txt, byte charset) } void TextCtrl::Remove(int pos, int size) { + DTIMING("Remove"); RemoveU(pos, size); Undodo(); } @@ -635,6 +638,7 @@ void TextCtrl::SelectAll() { } int TextCtrl::Paste(const WString& text) { + DTIMING("Paste"); if(IsReadOnly()) return 0; RemoveSelection(); int n = Insert(cursor, text); diff --git a/uppsrc/ide/Browser/TopicBase.cpp b/uppsrc/ide/Browser/TopicBase.cpp index dfd2fef68..8d3d52fa9 100644 --- a/uppsrc/ide/Browser/TopicBase.cpp +++ b/uppsrc/ide/Browser/TopicBase.cpp @@ -4,7 +4,7 @@ #define LTIMING(x) // DTIMING(x) #ifdef _DEBUG -#define LSLOW() Sleep(300) +#define LSLOW() // Sleep(300) #else #define LSLOW() #endif diff --git a/uppsrc/ide/Setup.cpp b/uppsrc/ide/Setup.cpp index 0bf096670..89e053610 100644 --- a/uppsrc/ide/Setup.cpp +++ b/uppsrc/ide/Setup.cpp @@ -447,7 +447,7 @@ void Ide::SetupFormat() { hlt.hlstyle.AddColumn("Bold").Ctrls