Assigning single chars between strings like "StrA[2] := StrB[2]" calls fpc_ansistr_unique, reducing performance a lot.
Original Reporter info from Mantis: Akira1364
-
Reporter name:
Original Reporter info from Mantis: Akira1364
- Reporter name:
Description:
program Example;
var
A: AnsiString = 'ABCD';
B: AnsiString = 'EFGH';
begin
A[2] := B[2];
end.
The assembler output for that program, using the flags "-Ci- -Cr- -g- -CX -XXs -O3 -a" is:
.section .text.n_main,"x"
.balign 16,0x90
.globl main
main:
.globl PASCALMAIN
PASCALMAIN:
.Lc2:
.Lc3:
.seh_proc main
.Ll1:
pushq %rbp
.seh_pushreg %rbp
.Lc4:
.Lc5:
movq %rsp,%rbp
.Lc6:
leaq -32(%rsp),%rsp
.seh_stackalloc 32
.seh_endprologue
call fpc_initializeunits
.Ll2:
leaq TC_
P
PROJECT1_$$_A(%rip),%rcxcall fpc_ansistr_unique
movq TC_
P
PROJECT1_$$_B(%rip),%rdxmovb 1(%rdx),%dl
movb %dl,1(%rax)
.Ll3:
call fpc_do_exit
nop
leaq (%rbp),%rsp
popq %rbp
ret
.seh_endproc
.Lc1:
.Lt1:
.Ll4:
Additional information:
I've also attached a more in-depth "benchmark" program that demonstrates the negative effect this has on things like StrUtils.ReverseString, in comparison to implementations of the same function where the kind of assignment that implicitly calls fpc_ansistr_unique is avoided.
Mantis conversion info:
- Mantis ID: 35775
- OS: Windows
- OS Build: 10
- Build: Trunk
- Platform: x86_64
- Version: 3.3.1
- Monitored by: » Akira1364 (Akira1364)