Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2020-09

FileUtil.FindAllFiles - changes strings inside

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

AlexeyT
procedure TFileSearcher.Search(ASearchPath: String; ASearchMask: String;
   ASearchSubDirs: Boolean; CaseSensitive: Boolean = False);
     while ASearchPath'' do begin
       p:=Pos(FPathSeparator,ASearchPath);
       if p<1 then
         p:=length(ASearchPath)+1;
       Dir:=ResolveDots(LeftStr(ASearchPath,p-1));
       Delete(ASearchPath,1,p);

you see that to iterate over all items in char-separated ASearchPath, code modifies str, ie deletes parts of it. It's slow! We should not modify str here. It's easy- save old-index, new-index, and get Copy(n1, n2-n1{+delta}).

Didn't see why ASearchMask is not "const", maybe same bad.

Alexey Torgashin

Reply by email

Bart
to AlexeyT
AM AlexeyT wrote
you see that to iterate over all items in char-separated ASearchPath, code modifies str, ie deletes parts of it. It's slow! We should not modify str here. It's easy- save old-index, new-index, and get Copy(n1, n2-n1{+delta}).

Premature optimization.
File IO is orders of magnitude slower that iteration over a string.

Bart

Reply by email

Ralf Quint
to Bart
Bart wrote 9 lines
On Mon, Sep 21, 2020 at 12:19 AM AlexeyT via lazarus wrote: > you see that to iterate over all items in char-separated ASearchPath, > code modifies str, ie deletes parts of it. It's slow! We should not > modify str here. It's easy- save old-index, new-index, and get Copy(n1, > n2-n1{+delta}). Premature optimization. File IO is orders of magnitude slower that iteration over a string.

+1

This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email