Forum > FPC development

[SOLVED] Simplified GetEnumNameCount

(1/1)

lagprogramming:
rtl/objpas/typinfo.pp has

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function GetEnumNameCount(enum1: PTypeInfo): SizeInt;var  PS: PShortString;  PT: PTypeData;  Count: SizeInt;begin  PT:=GetTypeData(enum1);  if enum1^.Kind=tkBool then    Result:=2  else    begin      Count:=0;      Result:=0;       PS:=@PT^.NameList;      While (PByte(PS)^<>0) do        begin          PS:=PShortString(pointer(PS)+PByte(PS)^+1);          Inc(Count);        end;      { the last string is the unit name }      Result := Count - 1;    end;end;
The above function has been simplified.
Variable "Count" has been replaced by "Result";
Removed the last "Result := Result - 1;" line by replacing "Result:=0;" with "Result:=-1;"
Switched "Result:=-1;" and "PS:=@PT^.NameList;" lines;
Variable "PT" has been removed by replacing "PS:=@PT^.NameList;" with "PS:=@GetTypeData(enum1)^.NameList;".
The function becomes:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function GetEnumNameCount(enum1: PTypeInfo): SizeInt;var  PS: PShortString;begin  if enum1^.Kind=tkBool then    Result:=2  else    begin      PS:=@GetTypeData(enum1)^.NameList;      Result:=-1;      While (PByte(PS)^<>0) do        begin          PS:=PShortString(pointer(PS)+PByte(PS)^+1);          Inc(Result);        end;    end;end;
The patch is attached to the message.

AlexTP:
Posted to https://gitlab.com/freepascal.org/fpc/source/-/issues/40411

Navigation

[0] Message Index

Go to full version