summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2016-05-30 12:08:52 +0200
committerErich Eckner <git@eckner.net>2016-05-30 12:08:52 +0200
commit4547093c9fcc350c3e5ab52e3f01dfa569524baf (patch)
tree0a27f58d1d72b2f0eaecc3121a9c148e081486dd
parentbce6635630de123e602b6b3e40473dccb6fd86ef (diff)
downloadunits-4547093c9fcc350c3e5ab52e3f01dfa569524baf.tar.xz
mystringlistunit.pas beschleunigt durch Aufbauen neuer Listen anstelle modifizieren vorhandener (grep, replace, uniq)
-rw-r--r--mystringlistunit.pas63
1 files 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 i<count do begin
+ while (i<count-1) and (self[i]=self[i+1]) do
+ inc(i);
+ tl.add(self[i]);
+ inc(i);
+ end;
+ end;
'd': begin // only keep duplicate lines, one for each group
- dup:=false;
- for i:=count-1 downto 0 do begin
- if (i>0) and (self[i]=self[i-1]) then begin
+ i:=0;
+ while i<count do begin
+ dup:=false;
+ while (i<count-1) and (self[i]=self[i+1]) do begin
dup:=true;
- delete(i);
- continue;
+ inc(i);
end;
- if not dup then
- delete(i);
- dup:=false;
+ if dup then
+ tl.add(self[i]);
+ inc(i);
end;
end;
else fehler('Unbekannte Option '''+c+''' für tMyStringList.uniq!');
end{of case};
+
+ clear;
+ for i:=0 to tl.count-1 do
+ add(tl[i]);
+
+ tl.free;
end;
procedure tMyStringlist.append(sl: tMyStringList);