Browse Source

* pos function speed up by a factor 40 :)

peter 26 years ago
parent
commit
2aca3b7908
1 changed files with 19 additions and 9 deletions
  1. 19 9
      rtl/inc/astrings.inc

+ 19 - 9
rtl/inc/astrings.inc

@@ -476,6 +476,8 @@ end;
 
 
 Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
 Function Pos (Const Substr : AnsiString; Const Source : AnsiString) : Longint;
 var
 var
+  substrlen,
+  maxi,
   i,j : longint;
   i,j : longint;
   e   : boolean;
   e   : boolean;
   S   : AnsiString;
   S   : AnsiString;
@@ -483,19 +485,24 @@ var
 begin
 begin
   i := 0;
   i := 0;
   j := 0;
   j := 0;
-  e := true;
-  if Length(SubStr)=0 then e := false;
-  while (e) and (i <= length (Source) - length (substr)) do
+  substrlen:=Length(SubStr);
+  maxi:=length(source)-substrlen;
+  e:=(substrlen>0);
+  while (e) and (i <= maxi) do
    begin
    begin
      inc (i);
      inc (i);
-     S:=copy(Source,i,length(Substr));
-     Se:=pointer(SubStr);
-     if AnsiStr_Compare(se,Pointer(S))=0 then
+     if Source[i]=SubStr[1] then
       begin
       begin
-        j := i;
-        e := false;
+        S:=copy(Source,i,substrlen);
+        Se:=pointer(SubStr);
+        if AnsiStr_Compare(se,Pointer(S))=0 then
+         begin
+           j := i;
+           break;
+         end;
       end;
       end;
    end;
    end;
+
   pos := j;
   pos := j;
 end;
 end;
 
 
@@ -619,7 +626,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.30  1999-07-05 20:04:21  peter
+  Revision 1.31  1999-10-04 20:48:18  peter
+    * pos function speed up by a factor 40 :)
+
+  Revision 1.30  1999/07/05 20:04:21  peter
     * removed temp defines
     * removed temp defines
 
 
   Revision 1.29  1999/06/14 00:47:33  peter
   Revision 1.29  1999/06/14 00:47:33  peter