Hi,

latest profiling of one of our FPC applications showed ReadInteger (in rtl/objpas/sysutils/sysformt.inc) to be a performance bottleneck. Using Pos(Fmt[chpos],'1234567890')<>0 to check if Fmt[chpos] is a digit is somewhat time consuming. I replaced it with two char comparisons with '0' and '9'.
The rest of the patch only unifies the casing of the variable chpos.

Markus
diff -Naur fpc-20080907/rtl/objpas/sysutils/sysformt.inc fpc-readintegerpatch/rtl/objpas/sysutils/sysformt.inc
--- fpc-20080907/rtl/objpas/sysutils/sysformt.inc	2008-04-07 01:00:27.000000000 +0200
+++ fpc-readintegerpatch/rtl/objpas/sysutils/sysformt.inc	2008-09-07 13:40:56.527074445 +0200
@@ -23,14 +23,14 @@
 
     begin
       If Value<>-1 then exit; // Was already read.
-      OldPos:=chPos;
-      While (Chpos<=Len) and
-            (Pos(Fmt[chpos],'1234567890')<>0) do inc(chpos);
-      If Chpos>len then
+      OldPos:=ChPos;
+      While (ChPos<=Len) and
+            (Fmt[ChPos]<='9') and (Fmt[ChPos]>='0') do inc(ChPos);
+      If ChPos>len then
         DoFormatError(feInvalidFormat);
-      If Fmt[Chpos]='*' then
+      If Fmt[ChPos]='*' then
         begin
-        If (Chpos>OldPos) or (ArgPos>High(Args)) then
+        If (ChPos>OldPos) or (ArgPos>High(Args)) then
           DoFormatError(feInvalidFormat);
         case Args[ArgPos].Vtype of
           vtInteger: Value := Args[ArgPos].VInteger;
@@ -40,11 +40,11 @@
           DoFormatError(feInvalidFormat);
         end;
         Inc(ArgPos);
-        Inc(chPos);
+        Inc(ChPos);
         end
       else
         begin
-        If (OldPos<chPos) Then
+        If (OldPos<ChPos) Then
           begin
           Val (Copy(Fmt,OldPos,ChPos-OldPos),value,code);
           // This should never happen !!
@@ -67,7 +67,7 @@
         If Value=-1 then DoFormatError(feMissingArgument);
         Index:=Value;
         Value:=-1;
-        Inc(Chpos);
+        Inc(ChPos);
         end;
 {$ifdef fmtdebug}
       Log ('Read index');
@@ -77,10 +77,10 @@
     Procedure ReadLeft;
 
     begin
-      If Fmt[chpos]='-' then
+      If Fmt[ChPos]='-' then
         begin
         left:=True;
-        Inc(chpos);
+        Inc(ChPos);
         end
       else
         Left:=False;
@@ -106,9 +106,9 @@
     Procedure ReadPrec;
 
     begin
-      If Fmt[chpos]='.' then
+      If Fmt[ChPos]='.' then
         begin
-        inc(chpos);
+        inc(ChPos);
           ReadInteger;
         If Value=-1 then
          Value:=0;
@@ -132,8 +132,8 @@
     Width:=-1;
     Prec:=-1;
     Value:=-1;
-    inc(chpos);
-    If Fmt[Chpos]='%' then
+    inc(ChPos);
+    If Fmt[ChPos]='%' then
       begin
         Result:='%';
         exit;                           // VP fix
@@ -198,15 +198,15 @@
 begin
   Result:='';
   Len:=Length(Fmt);
-  Chpos:=1;
+  ChPos:=1;
   OldPos:=1;
   ArgPos:=0;
-  While chpos<=len do
+  While ChPos<=len do
     begin
-    While (ChPos<=Len) and (Fmt[chpos]<>'%') do
-      inc(chpos);
+    While (ChPos<=Len) and (Fmt[ChPos]<>'%') do
+      inc(ChPos);
     If ChPos>OldPos Then
-      Result:=Result+Copy(Fmt,OldPos,Chpos-Oldpos);
+      Result:=Result+Copy(Fmt,OldPos,ChPos-Oldpos);
     If ChPos<Len then
       begin
       FChar:=ReadFormat;
@@ -348,7 +348,7 @@
             ToAdd:=ToAdd+space(Width-Length(ToAdd));
       Result:=Result+ToAdd;
       end;
-    inc(chpos);
-    Oldpos:=chpos;
+    inc(ChPos);
+    Oldpos:=ChPos;
     end;
 end;
_______________________________________________
fpc-devel maillist  -  [email protected]
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to