From a97e858b43648acce7d7fa098301e43500ec4dd6 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Thu, 16 Feb 2012 17:09:32 -0500 Subject: [PATCH] trying to reduce a little allocation --- js-assembler/assemble-expression.rkt | 36 ++++++++++++++++++---------- version.rkt | 2 +- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/js-assembler/assemble-expression.rkt b/js-assembler/assemble-expression.rkt index 78210bc..cf7075f 100644 --- a/js-assembler/assemble-expression.rkt +++ b/js-assembler/assemble-expression.rkt @@ -17,19 +17,29 @@ "M.p.label"] [(MakeCompiledProcedure? op) - (format "new RT.Closure(~a,~a,[~a],~a)" - (assemble-label (make-Label (MakeCompiledProcedure-label op)) - blockht) - (assemble-arity (MakeCompiledProcedure-arity op)) - (string-join (map - assemble-env-reference/closure-capture - ;; The closure values are in reverse order - ;; to make it easier to push, in bulk, into - ;; the environment (which is also in reversed order) - ;; during install-closure-values. - (reverse (MakeCompiledProcedure-closed-vals op))) - ",") - (assemble-display-name (MakeCompiledProcedure-display-name op)))] + (cond + ;; Small optimization: try to avoid creating the array if we know up front + ;; that the closure has no closed values. + [(null? (MakeCompiledProcedure-closed-vals op)) + (format "new RT.Closure(~a,~a,undefined,~a)" + (assemble-label (make-Label (MakeCompiledProcedure-label op)) + blockht) + (assemble-arity (MakeCompiledProcedure-arity op)) + (assemble-display-name (MakeCompiledProcedure-display-name op)))] + [else + (format "new RT.Closure(~a,~a,[~a],~a)" + (assemble-label (make-Label (MakeCompiledProcedure-label op)) + blockht) + (assemble-arity (MakeCompiledProcedure-arity op)) + (string-join (map + assemble-env-reference/closure-capture + ;; The closure values are in reverse order + ;; to make it easier to push, in bulk, into + ;; the environment (which is also in reversed order) + ;; during install-closure-values. + (reverse (MakeCompiledProcedure-closed-vals op))) + ",") + (assemble-display-name (MakeCompiledProcedure-display-name op)))])] [(MakeCompiledProcedureShell? op) (format "new RT.Closure(~a,~a,undefined,~a)" diff --git a/version.rkt b/version.rkt index 823b499..5887098 100644 --- a/version.rkt +++ b/version.rkt @@ -7,4 +7,4 @@ (provide version) (: version String) -(define version "1.142") +(define version "1.143")