From 4547093c9fcc350c3e5ab52e3f01dfa569524baf Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 30 May 2016 12:08:52 +0200 Subject: mystringlistunit.pas beschleunigt durch Aufbauen neuer Listen anstelle modifizieren vorhandener (grep, replace, uniq) --- mystringlistunit.pas | 63 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/mystringlistunit.pas b/mystringlistunit.pas index a98e452..7d63462 100644 --- a/mystringlistunit.pas +++ b/mystringlistunit.pas @@ -190,15 +190,25 @@ end; procedure tMyStringlist.grep(expr: string; invert: boolean); var + tl: tMyStringList; re: tRegExpr; i: longint; begin re:=tRegExpr.create; re.expression:=expr; - for i:=count-1 downto 0 do - if not invert xor re.exec(self[i]) then - delete(i); + re.compile; + + tl:=tMyStringList.create; + + for i:=0 to count-1 do + if invert xor re.exec(self[i]) then + tl.add(self[i]); re.free; + + clear; + for i:=0 to tl.count-1 do + add(tl[i]); + tl.free; end; function tMyStringlist.grepFirst(expr: string): string; @@ -220,40 +230,61 @@ end; procedure tMyStringlist.replace(von,nach: string); var + tl: tMyStringList; re: tRegExpr; i: longint; begin + tl:=tMyStringList.create; re:=tRegExpr.create; re.expression:=von; + re.compile; for i:=0 to count-1 do - self[i]:=re.replace(self[i],nach,true); + tl.add(re.replace(self[i],nach,true)); + + clear; + for i:=0 to tl.count-1 do + add(tl[i]); + tl.free; end; procedure tMyStringlist.uniq(c: char); var i: longint; + tl: tMyStringList; dup: boolean; begin + tl:=tMyStringList.create; case c of - '-': // only keep one line for each group - for i:=count-1 downto 1 do - if self[i]=self[i-1] then - delete(i); + '-': begin // only keep one line for each group + i:=0; + while i0) and (self[i]=self[i-1]) then begin + i:=0; + while i