[fpc-devel] Performance of string handling in trunk

Sven Barth pascaldragon at googlemail.com
Wed Jun 26 13:40:54 CEST 2013


Am 26.06.2013 12:38, schrieb Michael Schnell:
> On 06/26/2013 12:13 PM, Sven Barth wrote:
>> You do know that s2 will point to the same record of s1 after the 
>> assignment? The contents of the string record are not copied, only 
>> the pointer of s2 will change. See this example:
>>
>
> You are right (my testing program in pre-Unicode-Delphi does show 
> exactly this).
>
> But what I wanted to show is, that here more is done but just managing 
> the reference count. Regarding the dispute I had with dodi, he thus is 
> right that the length is not exactly _copied_over_, but the pointer is 
> managed in a way that the same length (and content) is shown. (I admit 
> that he is correct calling this just "reference counting".)
>
> Regarding the underlying discussion about RawByteString:
> If exactly this is done when assigning a normal String variable to a 
> RawByteString Variable, it happens exactly what I suppose (and dodi 
> seems to deny): the dynamic encoding type of the RawByteString 
> (target) will be set to the encoding type of the normal String 
> (source). Thus the encoding type is _not_ lost and (in principle) when 
> assigning a RawByteString to a normal String, the library would be 
> able to check the actual dynamic encoding type of the source against 
> the (static=dynamic) encoding type of the target and do a conversion 
> if appropriate. IMHO this would be a very sensible behavior.
It's the whole use of RawByteString that the encoding is kept. For all 
other string types the content will be converted. See also 
compare_defs_ext in compiler/defcmp.pas around line 445 (look for "don't 
convert ansistrings").

Regards,
Sven



More information about the fpc-devel mailing list