From e6da3bc43a66f23b75586c4b320208fed4c59579 Mon Sep 17 00:00:00 2001 From: Chris Double Date: Thu, 27 Mar 2008 14:55:14 +1300 Subject: [PATCH] Use cache in compiled-parser in peg --- extra/peg/peg.factor | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/extra/peg/peg.factor b/extra/peg/peg.factor index dd0b11fce3..fe58962f48 100755 --- a/extra/peg/peg.factor +++ b/extra/peg/peg.factor @@ -16,7 +16,6 @@ SYMBOL: ignore SYMBOL: compiled-parsers SYMBOL: packrat -SYMBOL: failed GENERIC: (compile) ( parser -- quot ) @@ -36,12 +35,9 @@ GENERIC: (compile) ( parser -- quot ) #! Look to see if the given parser has been compiled. #! If not, compile it to a temporary word, cache it, #! and return it. Otherwise return the existing one. - dup compiled-parsers get at [ - nip - ] [ - dup (compile) [ run-parser ] curry define-temp - [ swap compiled-parsers get set-at ] keep - ] if* ; + compiled-parsers get [ + (compile) [ run-parser ] curry define-temp + ] cache ; : compile ( parser -- word ) H{ } clone compiled-parsers [