@@ -6546,7 +6546,6 @@ function GetExtended(P: PUtf8Char; out err: integer): TSynExtended;
6546
6546
var
6547
6547
remdigit: integer;
6548
6548
frac, exp: PtrInt;
6549
- c: AnsiChar;
6550
6549
flags: set of (fNeg, fNegExp, fValid);
6551
6550
v64: Int64; // allows 64-bit resolution for the digits (match 80-bit extended)
6552
6551
d64: TSynExtended;
@@ -6558,106 +6557,84 @@ function GetExtended(P: PUtf8Char; out err: integer): TSynExtended;
6558
6557
frac := 0 ;
6559
6558
if P = nil then
6560
6559
goto e; // will return 0 but err=1
6561
- c := P^;
6562
- if c = ' ' then
6560
+ if P^ = ' ' then
6563
6561
repeat
6564
6562
inc(P);
6565
- c := P^;
6566
- until c <> ' ' ; // trailing spaces
6567
- if c = ' +' then
6568
- begin
6569
- inc(P);
6570
- c := P^;
6571
- end
6572
- else if c = ' -' then
6563
+ until P^ <> ' ' ; // trailing spaces
6564
+ if P^ = ' +' then
6565
+ inc(P)
6566
+ else if P^ = ' -' then
6573
6567
begin
6574
6568
inc(P);
6575
- c := P^;
6576
- if (c = ' I' ) and
6577
- (PWord(P + 1 )^ and $dfdf = ord(' N' ) + ord(' F' ) shl 8 ) then
6578
- begin
6579
- err := 0 ;
6580
- result := NegInfinity;
6581
- exit;
6582
- end ;
6583
6569
include(flags, fNeg);
6584
- end
6585
- else if c > ' 9' then
6586
- if (c = ' N' ) and
6587
- (PWord(P + 1 )^ and $dfdf = ord(' A' ) + ord(' N' ) shl 8 ) then
6588
- begin
6589
- err := 0 ;
6590
- result := NaN;
6591
- exit;
6592
- end
6593
- else if (c = ' I' ) and
6594
- (PWord(P + 1 )^ and $dfdf = ord(' N' ) + ord(' F' ) shl 8 ) then
6595
- begin
6596
- err := 0 ;
6597
- result := Infinity;
6598
- exit;
6570
+ end ;
6571
+ if P^ > ' 9' then
6572
+ case PCardinal(P)^ and $00dfdfdf of
6573
+ ord(' N' ) + ord(' A' ) shl 8 + ord(' N' ) shl 16 :
6574
+ begin
6575
+ err := 0 ;
6576
+ result := NaN;
6577
+ exit;
6578
+ end ;
6579
+ ord(' I' ) + ord(' N' ) shl 8 + ord(' F' ) shl 16 :
6580
+ begin
6581
+ err := 0 ;
6582
+ if fNeg in flags then
6583
+ result := NegInfinity
6584
+ else
6585
+ result := Infinity;
6586
+ exit;
6587
+ end ;
6599
6588
end ;
6600
6589
remdigit := 18 ; // v64=-9,223,372,036,854,775,808..+9,223,372,036,854,775,807
6601
6590
repeat
6602
- inc(P);
6603
- if (c >= ' 0' ) and
6604
- (c <= ' 9' ) then
6591
+ if byte(ord(P^) - ord(' 0' )) <= 9 then
6605
6592
begin
6606
- if remdigit = 0 then
6607
- if v64 < 922337203685477580 then // avoid 64-bit overflow
6608
- inc(remdigit); // but allow up to 19 digits if possible
6609
- dec(remdigit);
6593
+ if (remdigit <> 0 ) or // avoid 64-bit overflow, but allow 19 digits
6594
+ (v64 > 922337203685477580 ) then
6595
+ dec(remdigit);
6610
6596
if remdigit >= 0 then // over-required digits are just ignored
6611
6597
begin
6612
- dec(c, ord(' 0' ));
6613
- { $ifdef CPU64}
6614
- v64 := v64 * 10 ;
6615
- { $else}
6616
- v64 := v64 shl 3 + v64 + v64;
6617
- { $endif CPU64}
6618
- inc(v64, byte(c));
6619
- c := P^;
6598
+ v64 := v64 * 10 ; // FPC generates fast imul + mul on i386
6599
+ inc(v64, Int64(P^) - ord(' 0' ));
6620
6600
include(flags, fValid);
6621
6601
if frac <> 0 then
6622
6602
dec(frac); // digits after '.'
6603
+ inc(P);
6623
6604
continue;
6624
6605
end ;
6625
6606
if frac >= 0 then
6626
6607
inc(frac); // handle #############00000
6627
- c := P^ ;
6608
+ inc(P) ;
6628
6609
continue;
6629
6610
end ;
6630
- if c <> ' .' then
6611
+ if P^ <> ' .' then
6631
6612
break;
6613
+ inc(P);
6632
6614
if frac > 0 then
6633
6615
goto e; // will return partial value but err=1
6634
6616
dec(frac);
6635
- c := P^;
6636
6617
until false;
6637
6618
if frac < 0 then
6638
6619
inc(frac); // adjust digits after '.'
6639
- if (c = ' E' ) or
6640
- (c = ' e' ) then
6620
+ if ord(P^) or $20 = ord(' e' ) then
6641
6621
begin
6642
6622
exp := 0 ;
6643
6623
exclude(flags, fValid);
6644
- c := P^ ;
6645
- if c = ' +' then
6624
+ inc(P) ;
6625
+ if P^ = ' +' then
6646
6626
inc(P)
6647
- else if c = ' -' then
6627
+ else if P^ = ' -' then
6648
6628
begin
6649
6629
inc(P);
6650
6630
include(flags, fNegExp);
6651
6631
end ;
6652
6632
repeat
6653
- c := P^;
6654
- inc(P);
6655
- if (c < ' 0' ) or
6656
- (c > ' 9' ) then
6633
+ if byte(ord(P^) - ord(' 0' )) > 9 then
6657
6634
break;
6658
- dec(c, ord(' 0' ));
6659
- exp := (exp * 10 ) + byte(c);
6635
+ exp := (exp * 10 ) + ord(P^) - ord(' 0' );
6660
6636
include(flags, fValid);
6637
+ inc(P);
6661
6638
until false;
6662
6639
if fNegExp in flags then
6663
6640
dec(frac, exp)
@@ -6671,7 +6648,7 @@ function GetExtended(P: PUtf8Char; out err: integer): TSynExtended;
6671
6648
end ;
6672
6649
end ;
6673
6650
if (fValid in flags) and
6674
- (c = #0 ) then
6651
+ (P^ = #0 ) then
6675
6652
err := 0
6676
6653
else
6677
6654
e: err := 1 ; // return the (partial) value even if not ended with #0
0 commit comments