SamCoVT / TaliForth2

A Subroutine Threaded Code (STC) ANSI-like Forth for the 65c02
Other
29 stars 7 forks source link

String op improvements #141

Open patricksurry opened 1 month ago

patricksurry commented 1 month ago

Saves about 50 bytes overall. Simplifies CLEAVE (faster, smaller and avoids input manipulation). Shortens -LEADING/TRAILING: this slows it down a little after removing some inlining, but also because I switched to the shared jsr is_whitespace instead of the specific cmp #AscSP. I'm not sure if that was intentional but seemed like it should be symmetric with LEADING and CLEAVE?

The overall test cycles increase somewhat because -TRAILING is used in various tests, but I imagine in practice the CLEAVE improvement might be more important? Equally I could just undo the -TRAILING changes.

Cycle counts with simple test:

word before after
s" a b c " CLEAVE 1225 487
s" txt " -LEADING 354 234
s" txt " -TRAILING 224 430*

*337 with cmp #AscSp instead of jsr is_whitespace.

SamCoVT commented 1 month ago

One of the differences is that -TRAILING is an ANS standard word, while the others are Tali specific. The standard specifically mentions spaces, which are elsewhare defined as BL and the value 0x20. https://forth-standard.org/standard/string/MinusTRAILING

patricksurry commented 3 weeks ago

ah, that makes sense. so I'll switch -TRAILING back to only check for spaces. Does it make sense for -LEADING to behave in a similar same (only strip spaces specifcally) or should it continue to strip other whitespace as well?

SamCoVT commented 3 weeks ago

I agree that -TRAILING should use only spaces, but I'm fine with the other words skipping any whitespace and I think your changes look fine for those words.