Browse Source

* optimized fpc_val_sint_shortstr

Jonas Maebe 24 years ago
parent
commit
1b89398cec
1 changed files with 12 additions and 8 deletions
  1. 12 8
      rtl/inc/sstrings.inc

+ 12 - 8
rtl/inc/sstrings.inc

@@ -380,7 +380,7 @@ end;
 
 
 Function fpc_Val_SInt_ShortStr(DestSize: longint; Const S: ShortString; var Code: ValSInt): ValSInt; [public, alias:'FPC_VAL_SINT_SHORTSTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
 Function fpc_Val_SInt_ShortStr(DestSize: longint; Const S: ShortString; var Code: ValSInt): ValSInt; [public, alias:'FPC_VAL_SINT_SHORTSTR']; {$ifdef hascompilerproc} compilerproc; {$endif}
 var
 var
-  u, temp, prev, maxValue: ValUInt;
+  u, temp, prev, maxPrevValue, maxNewValue: ValUInt;
   base : byte;
   base : byte;
   negative : boolean;
   negative : boolean;
 begin
 begin
@@ -389,7 +389,11 @@ begin
   Code:=InitVal(s,negative,base);
   Code:=InitVal(s,negative,base);
   if Code>length(s) then
   if Code>length(s) then
    exit;
    exit;
-  maxValue := ValUInt(MaxUIntValue) div ValUInt(Base);
+  maxPrevValue := ValUInt(MaxUIntValue) div ValUInt(Base);
+  if (base = 10) then
+    maxNewValue := MaxSIntValue + ord(negative)
+  else
+    maxNewValue := MaxUIntValue;
   while Code<=Length(s) do
   while Code<=Length(s) do
    begin
    begin
      case s[Code] of
      case s[Code] of
@@ -402,11 +406,8 @@ begin
      Prev := Temp;
      Prev := Temp;
      Temp := Temp*ValUInt(base);
      Temp := Temp*ValUInt(base);
      If (u >= base) or
      If (u >= base) or
-        ((base = 10) and
-         (ValUInt(MaxSIntValue-u+ord(negative)) < Temp)) or
-        ((base <> 10) and
-         (ValUInt(MaxUIntValue-Temp) < u)) or
-        (prev > maxValue) Then
+        (ValUInt(maxNewValue-u) < Temp) or
+        (prev > maxPrevValue) Then
        Begin
        Begin
          fpc_Val_SInt_ShortStr := 0;
          fpc_Val_SInt_ShortStr := 0;
          Exit
          Exit
@@ -579,7 +580,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.16  2001-08-13 12:40:16  jonas
+  Revision 1.17  2001-11-16 15:09:47  jonas
+    * optimized fpc_val_sint_shortstr
+
+  Revision 1.16  2001/08/13 12:40:16  jonas
     * renamed some str(x,y) and val(x,y) helpers so the naming scheme is the
     * renamed some str(x,y) and val(x,y) helpers so the naming scheme is the
       same for all string types
       same for all string types
     + added the str(x,y) and val(x,y,z) helpers for int64/qword to
     + added the str(x,y) and val(x,y,z) helpers for int64/qword to