From: John Benediktsson Date: Tue, 9 Aug 2022 23:40:17 +0000 (-0700) Subject: xmode.marker: faster update-match-group X-Git-Tag: 0.99~1149 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=c489cb3bd4056bf72c43052db578d52bdbc62d53 xmode.marker: faster update-match-group --- diff --git a/basis/xmode/marker/marker.factor b/basis/xmode/marker/marker.factor index 32fae3c324..2b09ffdd55 100644 --- a/basis/xmode/marker/marker.factor +++ b/basis/xmode/marker/marker.factor @@ -110,11 +110,13 @@ M: regexp text-matches? : nth-match ( match regexp n -- slice/f ) match-group-regexp [ skip-first-match ] [ first-match ] bi* ; -: update-match-group ( str match regexp n -- str' ) - [ nth-match ] [ CHAR: 1 + "$%c" sprintf ] bi swap replace ; +:: update-match-group ( str match regexp n -- str' ) + n H{ } [ 1 + CHAR: $ swap "" 2sequence ] cache :> x + x str subseq? [ + x match "" like regexp n nth-match str replace + ] [ str ] if ; : update-match-groups ( str match regexp -- str' ) - [ >string ] dip dup #match-groups [ update-match-group ] 2with each-integer ; GENERIC: fixup-end ( match regexp end -- end' )