Browse Source

* made val for longints a bit faster

Jonas Maebe 24 years ago
parent
commit
e72e5a0cfa
1 changed files with 11 additions and 10 deletions
  1. 11 10
      rtl/inc/sstrings.inc

+ 11 - 10
rtl/inc/sstrings.inc

@@ -350,7 +350,7 @@ end;
 
 
 Function ValSignedInt(DestSize: longint; Const S: ShortString; var Code: ValSInt): ValSInt; [public, alias:'FPC_VAL_SINT_SHORTSTR'];
 Function ValSignedInt(DestSize: longint; Const S: ShortString; var Code: ValSInt): ValSInt; [public, alias:'FPC_VAL_SINT_SHORTSTR'];
 var
 var
-  u, temp, prev: ValUInt;
+  u, temp, prev, maxValue: ValUInt;
   base : byte;
   base : byte;
   negative : boolean;
   negative : boolean;
 begin
 begin
@@ -359,6 +359,7 @@ 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);
   while Code<=Length(s) do
   while Code<=Length(s) do
    begin
    begin
      case s[Code] of
      case s[Code] of
@@ -375,7 +376,7 @@ begin
          (MaxSIntValue-temp+ord(negative) < u)) or
          (MaxSIntValue-temp+ord(negative) < u)) or
         ((base <> 10) and
         ((base <> 10) and
          (ValUInt(MaxUIntValue-Temp) < u)) or
          (ValUInt(MaxUIntValue-Temp) < u)) or
-        (prev > ValUInt(MaxUIntValue) div ValUInt(Base)) Then
+        (prev > maxValue) Then
        Begin
        Begin
          ValSignedInt := 0;
          ValSignedInt := 0;
          Exit
          Exit
@@ -390,20 +391,17 @@ begin
   If Not(Negative) and (base <> 10) Then
   If Not(Negative) and (base <> 10) Then
    {sign extend the result to allow proper range checking}
    {sign extend the result to allow proper range checking}
     Case DestSize of
     Case DestSize of
-      1: If (ValSignedInt > High(ShortInt)) and (ValSignedInt <= High(Byte)) Then
-           ValSignedInt := ValSignedInt or (MaxUIntValue xor High(Byte));
-      2: If (ValSignedInt > High(Integer)) and (ValSignedInt <= High(Word)) Then
-           ValSignedInt := ValSignedInt or (MaxUIntValue xor High(Word));
+      1: ValSignedInt := shortint(ValSignedInt);
+      2: ValSignedInt := smallint(ValSignedInt);
 {     Uncomment the folling once full 64bit support is in place
 {     Uncomment the folling once full 64bit support is in place
-      4: If (ValSignedInt > High(Longint)) and (ValSignedInt <= High(Cardinal)) Then
-           ValSignedInt := ValSignedInt or (MaxUIntValue xor High(Cardinal));}
+      4: ValSignedInt := longint(ValSignedInt);}
     End;
     End;
 end;
 end;
 
 
 
 
 Function ValUnsignedInt(Const S: ShortString; var Code: ValSInt): ValUInt; [public, alias:'FPC_VAL_UINT_SHORTSTR'];
 Function ValUnsignedInt(Const S: ShortString; var Code: ValSInt): ValUInt; [public, alias:'FPC_VAL_UINT_SHORTSTR'];
 var
 var
-  u, prev: ValUInt;
+  u, prev, maxValue: ValUInt;
   base : byte;
   base : byte;
   negative : boolean;
   negative : boolean;
 begin
 begin
@@ -552,7 +550,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.8  2000-12-09 20:52:41  florian
+  Revision 1.9  2001-03-03 12:38:53  jonas
+    * made val for longints a bit faster
+
+  Revision 1.8  2000/12/09 20:52:41  florian
     * val for dword and qword didn't handle the max values
     * val for dword and qword didn't handle the max values
       correctly
       correctly
     * val for qword works again
     * val for qword works again