String pooling does not make use of the compatibility between PChar and String.
Original Reporter info from Mantis: runewalsh
Description:
The code
var
xs, xs2, xs3: string;
begin
xs := 'some string';
xs2 := 'some string';
xs3 := 'some string';
end.
puts only one 'some string' constant inside .rdata.
The code
var
xpc, xpc2, xpc3: PChar;
begin
xpc := 'some string';
xpc2 := 'some string';
xpc3 := 'some string';
end.
stores only one 'some string' (this time PChar-esque, without string header), too.
But
var
xs, xs2, xs3: string;
xpc, xpc2, xpc3: PChar;
begin
xs := 'some string';
xs2 := 'some string';
xs3 := 'some string';
xpc := 'some string';
xpc2 := 'some string';
xpc3 := 'some string';
end.
generates two constants, one for ‘string’ and one for ‘PChar’.
This is superfluous, as ‘PChar’ could reuse ‘string’ data. Note that both are read-only, so even now xpc[0] := 'S' will SIGSEGV and xs[1] := 'S' will copy the string.
Mantis conversion info:
-
Mantis ID: 38480
-
Build: 3.3.1-r47986 [2021/01/03]
-
Version: 3.3.1