cleaned up and optimized fix for #1354 (d91ccd4003)

This commit is contained in:
Michael Ficarra 2011-05-15 21:46:35 -04:00
parent 004f13f0fc
commit 2ac74356bd
2 changed files with 15 additions and 15 deletions

View File

@ -1728,22 +1728,21 @@
In.prototype.children = ['object', 'array'];
In.prototype.invert = NEGATE;
In.prototype.compileNode = function(o) {
var isArray, obj, splat, _i, _len, _ref2;
isArray = this.array instanceof Value && this.array.isArray();
if (isArray) {
var hasSplat, obj, _i, _len, _ref2;
if (this.array instanceof Value && this.array.isArray()) {
_ref2 = this.array.base.objects;
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
obj = _ref2[_i];
if (obj instanceof Splat) {
splat = obj;
hasSplat = true;
break;
}
}
if (!hasSplat) {
return this.compileOrTest(o);
}
}
if (isArray && !splat) {
return this.compileOrTest(o);
} else {
return this.compileLoopTest(o);
}
return this.compileLoopTest(o);
};
In.prototype.compileOrTest = function(o) {
var cmp, cnj, i, item, ref, sub, tests, _ref2, _ref3;

View File

@ -1349,12 +1349,13 @@ exports.In = class In extends Base
invert: NEGATE
compileNode: (o) ->
isArray = @array instanceof Value and @array.isArray()
splat = obj for obj in @array.base.objects when obj instanceof Splat if isArray
if isArray and not splat
@compileOrTest o
else
@compileLoopTest o
if @array instanceof Value and @array.isArray()
for obj in @array.base.objects when obj instanceof Splat
hasSplat = yes
break
# `compileOrTest` only if we have an array literal with no splats
return @compileOrTest o unless hasSplat
@compileLoopTest o
compileOrTest: (o) ->
[sub, ref] = @object.cache o, LEVEL_OP