retro.forth: refactor a bit of common code to save some size

FossilOrigin-Name: 561a9c1ff2235d4fe7398d896d10d3f7e13b5318b76f512ddd10647b81c0f6ab
This commit is contained in:
crc 2020-02-13 13:50:20 +00:00
parent 141fca1dc6
commit 1f000ccd3b
3 changed files with 537 additions and 539 deletions

View file

@ -876,19 +876,17 @@ a given substring is in a string.
~~~
{{
:extract dup-pair here swap copy here over + #0 swap store ;
:check &extract dip [ &n:inc dip ] dip here s:hash over eq? ;
:mask rot rot [ [ swap &or dip ] dip ] dip ;
:location rot rot [ [ swap [ over n:zero? and ] dip swap [ nip dup ] if ] dip ] dip ;
:setup #0 rot rot &s:length &s:hash bi s:empty buffer:set [ over s:length ] dip swap ;
---reveal---
:s:contains-string? (ss-f)
[ setup
[ &extract dip [ &n:inc dip ] dip here s:hash over eq? mask ] times
] buffer:preserve drop-pair drop ;
[ setup [ check mask ] times ] buffer:preserve drop-pair drop ;
:s:index-of-string (ss-n)
over [ [ setup
[ &extract dip [ &n:inc dip ] dip here s:hash over eq? location ] times
] buffer:preserve drop-pair drop ] dip - n:dec #-1 n:max ;
over [ [ setup [ check location ] times ] buffer:preserve
drop-pair drop ] dip - n:dec #-1 n:max ;
}}
~~~

BIN
ngaImage

Binary file not shown.

File diff suppressed because it is too large Load diff