From 40b616e9ead66225734e71a41e6698315d2b6c1f Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Mon, 27 Feb 2012 14:39:40 -0500 Subject: [PATCH] minor: optimizing the splice a little more for code generation --- js-assembler/assemble.rkt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/js-assembler/assemble.rkt b/js-assembler/assemble.rkt index 713b312..b526c21 100644 --- a/js-assembler/assemble.rkt +++ b/js-assembler/assemble.rkt @@ -588,10 +588,19 @@ EOF (format "M.e.length-=~a;" (assemble-oparg (PopEnvironment-n stmt) blockht))])] [else - (format "M.e.splice(M.e.length-(~a+~a),~a);" - (assemble-oparg (PopEnvironment-skip stmt) blockht) - (assemble-oparg (PopEnvironment-n stmt) blockht) - (assemble-oparg (PopEnvironment-n stmt) blockht))]))] + (define skip (PopEnvironment-skip stmt)) + (define n (PopEnvironment-n stmt)) + (cond + [(and (Const? skip) (Const? n)) + (format "M.e.splice(M.e.length-~a,~a);" + (+ (ensure-natural (Const-const skip)) + (ensure-natural (Const-const n))) + (Const-const n))] + [else + (format "M.e.splice(M.e.length-(~a+~a),~a);" + (assemble-oparg skip blockht) + (assemble-oparg n blockht) + (assemble-oparg n blockht))])]))] [(PushImmediateOntoEnvironment? stmt) (format "M.e.push(~a);"