Optimize stpcpy's size and speed
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
#include <string.h>
|
||||
|
||||
char * __fastcall__ stpcpy (char * dst, const char * src)
|
||||
{
|
||||
strcpy (dst, src);
|
||||
return dst + strlen (src);
|
||||
}
|
||||
22
libsrc/common/stpcpy.s
Normal file
22
libsrc/common/stpcpy.s
Normal file
@@ -0,0 +1,22 @@
|
||||
;
|
||||
; Colin Leroy-Mira, 4 Sept. 2024
|
||||
;
|
||||
; char* stpcpy (char* dest, const char* src);
|
||||
;
|
||||
|
||||
.export _stpcpy
|
||||
.import _strcpy
|
||||
|
||||
.importzp tmp1, ptr2
|
||||
|
||||
_stpcpy:
|
||||
jsr _strcpy
|
||||
|
||||
ldx ptr2+1 ; Load dest pointer's last high byte
|
||||
tya ; Get the last offset strcpy wrote to
|
||||
|
||||
clc
|
||||
adc ptr2 ; Add to low byte value
|
||||
bcc :+
|
||||
inx
|
||||
: rts ; Return pointer to dest's terminator
|
||||
@@ -25,6 +25,9 @@ L1: lda (ptr1),y
|
||||
inc ptr2+1
|
||||
bne L1
|
||||
|
||||
L9: lda ptr2 ; X still contains high byte
|
||||
rts
|
||||
L9: lda ptr2 ; X still contains dest's original high byte
|
||||
|
||||
; On exit, we want AX to be dest (as this is what strcpy returns).
|
||||
; We also want (ptr2),y to still point to dest's terminator, as this
|
||||
; is used by stpcpy().
|
||||
rts
|
||||
|
||||
Reference in New Issue
Block a user