From 31080c18f7ded0c86a44176ecf3cb1671bf377a1 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Fri, 17 Sep 2021 18:36:18 +0200 Subject: [PATCH] fix #89 - improve algo complexity of computing "text" completions --- src/u_synmemo.pas | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/u_synmemo.pas b/src/u_synmemo.pas index 10bd7ba6..b5e162e2 100644 --- a/src/u_synmemo.pas +++ b/src/u_synmemo.pas @@ -2884,7 +2884,9 @@ var i: integer; o: TObject; s: string; + w: string; r: TStringRange = (ptr:nil; pos:0; len: 0); + h: TStringHashSet; const c: TSysCharSet = ['A'..'Z', 'a'..'z', '_']; begin @@ -2910,13 +2912,21 @@ begin if fTextCompletion then begin - r := TStringRange.create(lines.Text); - while not r.empty do + h := TStringHashSet.create(); + for i := 0 to lines.Count-1 do begin - s := r.popUntil(c)^.takeWhile(c).yield; - if (s.length > fTextCompletionMinLength) and fCompletion.ItemList.IndexOfName(s).equals(-1) then - fCompletion.ItemList.AddObject(s, TObject(PtrUint(dckText))); + r := TStringRange.create(lines[i]); + while not r.empty do + begin + w := r.popUntil(c)^.takeWhile(c).yield; + if (w.length > fTextCompletionMinLength) and not h.contains(w) then + begin + h.insert(w); + fCompletion.ItemList.AddObject(w, TObject(PtrUint(dckText))); + end; + end; end; + h.Free; end; end;