View Issue Details

IDProjectCategoryView StatusLast Update
0037562FPCPackagespublic2020-08-13 12:14
ReporterCudaText man Assigned ToMichael Van Canneyt  
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037562: Small optimization for fpjson
Descriptionhttps://github.com/graemeg/freepascal/blob/master/packages/fcl-json/src/fpjson.pp
       'u' : begin
                W:=Copy(S,I+1,4);
                Inc(I,4);
                u2:=StrToInt('$'+W);


I suggest to avoid str alloc here via this function from me

function BufferHexToInt(p: PWideChar; Len: integer): integer; //Alexey
var
  N, i: integer;
  ch: WideChar;
begin
  Result:= 0;
  for i:= 1 to Len do
  begin
    ch:= p^;
    case ch of
      '0'..'9':
        N:= Ord(ch)-Ord('0');
      'a'..'f':
        N:= Ord(ch)-(Ord('a')-10);
      'A'..'F':
        N:= Ord(ch)-(Ord('A')-10);
      else
        exit(-1);
    end;
    Inc(p);
    Result:= Result*16+N;
  end;
end;

TagsNo tags attached.
Fixed in Revision46412.
FPCOldBugId
FPCTarget3.2.2
Attached Files

Activities

Michael Van Canneyt

2020-08-13 10:11

administrator   ~0124822

We will need 2 functions, because your code will not work in pas2js, and fpjson is shared between the native compiler and pas2js.

Michael Van Canneyt

2020-08-13 10:13

administrator   ~0124823

Note: S is an ansistring, not a unicodestring/widestring, so the function must be adapted to use PAnsiChar

CudaText man_

2020-08-13 11:54

reporter   ~0124829

This can be used in pas2js?

function BufferHexToInt(const S: string; Index, Len: integer): integer;
var
  N, i: integer;
  ch: char;
begin
  Result:= 0;
  for i:= Index to Min(Index+Len-1, Length(S)) do
  begin
    ch:= S[i];
    case ch of
      '0'..'9':
        N:= Ord(ch)-Ord('0');
      'a'..'f':
        N:= Ord(ch)-(Ord('a')-10);
      'A'..'F':
        N:= Ord(ch)-(Ord('A')-10);
      else
        exit(-1);
    end;
    Result:= Result*16+N;
  end;
end;  

Michael Van Canneyt

2020-08-13 12:14

administrator   ~0124832

Fixed. Used your original version, for pas2js the string parsing is done differently anyway. Thank you !

Issue History

Date Modified Username Field Change
2020-08-13 02:29 CudaText man New Issue
2020-08-13 10:09 Michael Van Canneyt Assigned To => Michael Van Canneyt
2020-08-13 10:09 Michael Van Canneyt Status new => assigned
2020-08-13 10:11 Michael Van Canneyt Note Added: 0124822
2020-08-13 10:13 Michael Van Canneyt Note Added: 0124823
2020-08-13 11:54 CudaText man_ Note Added: 0124829
2020-08-13 12:14 Michael Van Canneyt Status assigned => resolved
2020-08-13 12:14 Michael Van Canneyt Resolution open => fixed
2020-08-13 12:14 Michael Van Canneyt Fixed in Version => 3.3.1
2020-08-13 12:14 Michael Van Canneyt Fixed in Revision => 46412.
2020-08-13 12:14 Michael Van Canneyt FPCTarget => 3.2.2
2020-08-13 12:14 Michael Van Canneyt Note Added: 0124832