Actually caching the splatted constructor this time.

This commit is contained in:
Timothy Jones
2010-09-12 01:49:25 +12:00
parent d1f31c5143
commit e5837b4ee9
3 changed files with 8 additions and 2 deletions

View File

@@ -547,7 +547,7 @@
a = o.scope.freeVariable(); a = o.scope.freeVariable();
b = o.scope.freeVariable(); b = o.scope.freeVariable();
c = o.scope.freeVariable(); c = o.scope.freeVariable();
return "" + (this.first) + "(function() {\n" + (this.idt(1)) + "var ctor = function(){};\n" + (this.idt(1)) + "__extends(ctor, " + (a) + " = " + (meth) + ");\n" + (this.idt(1)) + "return typeof (" + (b) + " = " + (meth) + ".apply(" + (c) + " = new ctor, " + (this.compileSplatArguments(o)) + ")) === \"object\" ? " + (b) + " : " + (c) + ";\n" + (this.tab) + "})." + (mentionsArgs ? 'apply(this, arguments)' : 'call(this)') + (this.last); return "" + (this.first) + "(function() {\n" + (this.idt(1)) + "var ctor = function(){};\n" + (this.idt(1)) + "__extends(ctor, " + (a) + " = " + (meth) + ");\n" + (this.idt(1)) + "return typeof (" + (b) + " = " + (a) + ".apply(" + (c) + " = new ctor, " + (this.compileSplatArguments(o)) + ")) === \"object\" ? " + (b) + " : " + (c) + ";\n" + (this.tab) + "})." + (mentionsArgs ? 'apply(this, arguments)' : 'call(this)') + (this.last);
} else { } else {
return "" + (this.first) + (this.prefix()) + (meth) + ".apply(" + (obj) + ", " + (this.compileSplatArguments(o)) + ")" + (this.last); return "" + (this.first) + (this.prefix()) + (meth) + ".apply(" + (obj) + ", " + (this.compileSplatArguments(o)) + ")" + (this.last);
} }

View File

@@ -486,7 +486,7 @@ exports.CallNode = class CallNode extends BaseNode
#{@first}(function() { #{@first}(function() {
#{@idt(1)}var ctor = function(){}; #{@idt(1)}var ctor = function(){};
#{@idt(1)}__extends(ctor, #{a} = #{meth}); #{@idt(1)}__extends(ctor, #{a} = #{meth});
#{@idt(1)}return typeof (#{b} = #{meth}.apply(#{c} = new ctor, #{ @compileSplatArguments(o) })) === "object" ? #{b} : #{c}; #{@idt(1)}return typeof (#{b} = #{a}.apply(#{c} = new ctor, #{ @compileSplatArguments(o) })) === "object" ? #{b} : #{c};
#{@tab}}).#{ if mentionsArgs then 'apply(this, arguments)' else 'call(this)'}#{@last} #{@tab}}).#{ if mentionsArgs then 'apply(this, arguments)' else 'call(this)'}#{@last}
""" """
else else

View File

@@ -238,3 +238,9 @@ type = new Type args...
ok type and type instanceof Type ok type and type instanceof Type
ok v is args[i] for v, i in type.args ok v is args[i] for v, i in type.args
# Ensure that constructors invoked with splats cache the function.
called = 0
get = -> if called++ then false else class Type
new get() args...