Skip to content

Rewrite fpc_shortstr_concat_multi for AVR to not use a temporary shortstring to reduce RAM usage.

ccrause requested to merge ccrause/fpc-source:shortstrconcatmulti into main

The RTL procedure fpc_shortstr_concat_multi currently uses a temporary shortstring which consumes 257 bytes of stack space. On memory constrained system such as AVR this is a high resource cost. This patch presents fpc_shortstr_concat_multi rewritten to eliminate the use of a temporary shortstring by first moving the first occurrence of dests as source string to the appropriate location in dests, then using this offset as source when dests appears as source.

Since eliminating a temporary shortstring is in principle an improvement, this could in principle benefit all targets. Below a code size check (with default -O2) of the new fpc_shortstr_concat_multi for selected different systems (when included in generic.inc):

System original code size [bytes] modified code size [bytes]
avr-embedded 554 508
arm-linux 304 348
m68k-linux 208 296
riscv32-linux 440 456
x86_64-linux 465 413
xtensa-freertos 232 235

Clearly the code size benefit of this patch depends on the target system. Since there is sometimes a code size increase, the executions speed changes were not measured, and the use of shortstrings are probably not that prevalent on the larger systems, this patch is only implemented for AVR for now.

Merge request reports