string assignment can sometimes reuse old string alocated memory

This commit is contained in:
FeralChild64 committed 2020-07-18 13:55:19 +02:00
1 parent 60f30f22fb
commit c50595ab2d
4 files changed
+97 -59

No files matched your search

+27 -59
View File
@@ -259,24 +259,41 @@ cmd_let_assign_string_not_same:
cmd_let_assign_string_not_text_area:
// Check if size of both strings equals and the old on is above FRETOP
// Check if the new string is a temporary one - if so, reuse alocation
// XXX
// Check if new one is at least 3 bytes shorter and the old one is above FRETOP
// Check if the old string belongs to the string area (is above FRETOP)
// XXX
jsr varstr_cmp_fretop
bcc cmd_let_assign_string_no_optimizations
// Check if the new string is a temporary one - if so, reuse already done alocation
// FALLTROUGH
// XXX
cmd_let_assign_string_try_reuse:
// No special case optimization is possible
// Free the memory belonging to the old string
// Check if size of both strings equals
lda DSCPNT+0
cmp __FAC1
bne cmd_let_assign_string_try_reuse_unsuccesful
// Size of both string equals, the old one belongs to the string area - simply reuse it
jmp helper_let_strvarcpy
cmd_let_assign_string_try_reuse_unsuccesful:
// XXX consider another optimization first: parial memory reuse
// No special case optimization is possible - but first get rid of the old string
jsr varstr_free
// And allocate memory for the new string
// FALLTROUGH
cmd_let_assign_string_no_optimizations:
// Allocate memory for the new string
lda __FAC1+0
ldy #$00
@@ -294,55 +311,6 @@ cmd_let_assign_string_not_text_area:
jsr varstr_alloc
// Copy the string
// Copy the string and quit
#if CONFIG_MEMORY_MODEL_60K
ldx #<VARPNT
ldy #$02
jsr peek_under_roms
sta DSCPNT+2
dey
jsr peek_under_roms
sta DSCPNT+1
dey
// .Y is now 0 - copy the content
!:
ldx #<__FAC1+1
jsr peek_under_roms
ldx #<DSCPNT+1
jsr poke_under_roms
iny
cpy __FAC1+0
bne !-
#elif CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K
jsr helper_let_strvarcpy
#else // CONFIG_MEMORY_MODEL_38K
// Retrieve pointer to destination
ldy #$02
lda (VARPNT), y
sta DSCPNT+2
dey
lda (VARPNT), y
sta DSCPNT+1
dey
// .Y is now 0 - copy the content
!:
lda (__FAC1+1),y
sta (DSCPNT+1),y
iny
cpy __FAC1+0
bne !-
#endif
rts
jmp helper_let_strvarcpy
@@ -0,0 +1,32 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Helper routine to copy string descriptor, for LET command
//
#if CONFIG_MEMORY_MODEL_38K
helper_let_strdesccpy:
ldy #$02
lda (VARPNT), y
sta DSCPNT+2
dey
lda (VARPNT), y
sta DSCPNT+1
dey
// .Y is now 0 - copy the content
!:
lda (__FAC1+1),y
sta (DSCPNT+1),y
iny
cpy __FAC1+0
bne !-
rts
#endif
@@ -0,0 +1,37 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Helper routine to copy string descriptor, for LET command
//
#if CONFIG_MEMORY_MODEL_60K
helper_let_strdesccpy:
ldx #<VARPNT
ldy #$02
jsr peek_under_roms
sta DSCPNT+2
dey
jsr peek_under_roms
sta DSCPNT+1
dey
// .Y is now 0 - copy the content
!:
ldx #<__FAC1+1
jsr peek_under_roms
ldx #<DSCPNT+1
jsr poke_under_roms
iny
cpy __FAC1+0
bne !-
rts
#endif