From d066056a22bfea38901da258bd039fc4588c8251 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 25 Oct 2017 23:52:33 -0700 Subject: awk: retrieve range flag vector once per iteration. This is an improvement in the code generation related to awk range expressions. Previously, on each iteration, for each range expression, the awk state structure is accessed to retrieve the flag vector, which is then kept in a lexical variable. With this change, the retrieval is done once for all the range expressions, which share the same variable to access it. * share/txr/stdlib/awk.tl (sys:awk-compile-time): New slot, rng-vec-temp. (sys:awk-mac-let): Alias the flag variable to a simplified vecref expression which accesses the vector assumed to have been retrieved and bound to the variable named by the rng-vec-temp gensym. (awk): Add one more variable binding into the scope of the ranges: the binding of the variable named by the rng-vec-temp gensym, to an expression which retrieves the rng-vec from the Awk run-time state structure. --- share/txr/stdlib/awk.tl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/share/txr/stdlib/awk.tl b/share/txr/stdlib/awk.tl index 57e7c271..88509ccd 100644 --- a/share/txr/stdlib/awk.tl +++ b/share/txr/stdlib/awk.tl @@ -61,6 +61,7 @@ cond-actions (nranges 0) (rng-rec-temp (gensym)) + (rng-vec-temp (gensym)) rng-expr-temps rng-exprs outer-env) @@ -334,7 +335,7 @@ (set-diff te-ef te-ff) 'functions) (push rng-temp (qref ,awc rng-expr-temps)) - (push ^(placelet ((flag (vecref (qref ,',aws-sym rng-vec) ,ix))) + (push ^(placelet ((flag (vecref ,(qref ,awc rng-vec-temp) ,ix))) (let ((,flag-old flag) ,flag-act ,flag-deact ,*(if need-mid ^(,flag-mid (,from-expr-val ,from-expr-ex)))) ,*(if need-mid @@ -474,9 +475,10 @@ ^((,awk-fun (lambda (,aws-sym) ,(if awc.rng-exprs ^(let* ((,awc.rng-rec-temp rec) - ,*(nreverse - (zip awc.rng-expr-temps - awc.rng-exprs))) + (,awc.rng-vec-temp (qref ,aws-sym rng-vec)) + ,*(nreverse + (zip awc.rng-expr-temps + awc.rng-exprs))) ,p-actions-xform) p-actions-xform)))))) ,*awc.begin-actions -- cgit v1.2.3