mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Issue #609. Slightly faster implementation of ||= and &&=
This commit is contained in:
parent
f496cc229b
commit
975b82f09b
7 changed files with 30 additions and 30 deletions
|
@ -20,7 +20,7 @@
|
|||
exports.VERSION = '0.9.1';
|
||||
lexer = new Lexer();
|
||||
exports.compile = (compile = function(code, options) {
|
||||
options = options || {};
|
||||
options || (options = {});
|
||||
try {
|
||||
return (parser.parse(lexer.tokenize(code))).compile(options);
|
||||
} catch (err) {
|
||||
|
|
|
@ -220,7 +220,7 @@
|
|||
var o;
|
||||
optionParser = new optparse.OptionParser(SWITCHES, BANNER);
|
||||
o = (options = optionParser.parse(process.argv.slice(2, process.argv.length)));
|
||||
options.compile = options.compile || (!!o.output);
|
||||
options.compile || (options.compile = (!!o.output));
|
||||
options.run = !(o.compile || o.print || o.lint);
|
||||
options.print = !!(o.print || (o.eval || o.stdio && o.compile));
|
||||
return (sources = options.arguments);
|
||||
|
|
|
@ -324,7 +324,7 @@
|
|||
if (value && value.match(CODE)) {
|
||||
this.tagParameters();
|
||||
}
|
||||
value = value || this.chunk.substr(0, 1);
|
||||
value || (value = this.chunk.substr(0, 1));
|
||||
this.i += value.length;
|
||||
spaced = this.prev() && this.prev().spaced;
|
||||
tag = value;
|
||||
|
@ -435,7 +435,7 @@
|
|||
};
|
||||
Lexer.prototype.balancedString = function(str, delimited, options) {
|
||||
var _d, _e, _f, _g, close, i, levels, open, pair, slash;
|
||||
options = options || {};
|
||||
options || (options = {});
|
||||
slash = delimited[0][0] === '/';
|
||||
levels = [];
|
||||
i = 0;
|
||||
|
@ -478,7 +478,7 @@
|
|||
};
|
||||
Lexer.prototype.interpolateString = function(str, options) {
|
||||
var _d, _e, _f, _g, _h, _i, escaped, expr, i, idx, inner, interpolated, lexer, nested, pi, quote, tag, tok, token, tokens, value;
|
||||
options = options || {};
|
||||
options || (options = {});
|
||||
if (str.length < 3 || !starts(str, '"')) {
|
||||
return this.token('STRING', str);
|
||||
} else {
|
||||
|
|
44
lib/nodes.js
44
lib/nodes.js
|
@ -48,7 +48,7 @@
|
|||
};
|
||||
BaseNode.prototype.compileReference = function(o, options) {
|
||||
var compiled, pair, reference;
|
||||
options = options || {};
|
||||
options || (options = {});
|
||||
pair = (function() {
|
||||
if (!((this instanceof CallNode || this.contains(function(n) {
|
||||
return n instanceof CallNode;
|
||||
|
@ -105,7 +105,7 @@
|
|||
};
|
||||
BaseNode.prototype.toString = function(idt, override) {
|
||||
var _b, _c, _d, _e, child, children;
|
||||
idt = idt || '';
|
||||
idt || (idt = '');
|
||||
children = (function() {
|
||||
_b = []; _d = this.collectChildren();
|
||||
for (_c = 0, _e = _d.length; _c < _e; _c++) {
|
||||
|
@ -207,7 +207,7 @@
|
|||
return this;
|
||||
};
|
||||
Expressions.prototype.compile = function(o) {
|
||||
o = o || {};
|
||||
o || (o = {});
|
||||
return o.scope ? Expressions.__superClass__.compile.call(this, o) : this.compileRoot(o);
|
||||
};
|
||||
Expressions.prototype.compileNode = function(o) {
|
||||
|
@ -318,7 +318,7 @@
|
|||
ValueNode = function(_b, _c) {
|
||||
this.properties = _c;
|
||||
this.base = _b;
|
||||
this.properties = this.properties || [];
|
||||
this.properties || (this.properties = []);
|
||||
return this;
|
||||
};
|
||||
__extends(ValueNode, BaseNode);
|
||||
|
@ -382,7 +382,7 @@
|
|||
only = del(o, 'onlyFirst');
|
||||
op = del(o, 'operation');
|
||||
props = only ? this.properties.slice(0, this.properties.length - 1) : this.properties;
|
||||
o.chainRoot = o.chainRoot || this;
|
||||
o.chainRoot || (o.chainRoot = this);
|
||||
if (this.parenthetical && !props.length) {
|
||||
this.base.parenthetical = true;
|
||||
}
|
||||
|
@ -445,7 +445,7 @@
|
|||
this.isNew = false;
|
||||
this.isSuper = variable === 'super';
|
||||
this.variable = this.isSuper ? null : variable;
|
||||
this.args = this.args || [];
|
||||
this.args || (this.args = []);
|
||||
this.compileSplatArguments = function(o) {
|
||||
return SplatNode.compileSplattedArray.call(this, this.args, o);
|
||||
};
|
||||
|
@ -552,7 +552,7 @@
|
|||
AccessorNode.prototype.compileNode = function(o) {
|
||||
var name, namePart;
|
||||
name = this.name.compile(o);
|
||||
o.chainRoot.wrapped = o.chainRoot.wrapped || this.soakNode;
|
||||
o.chainRoot.wrapped || (o.chainRoot.wrapped = this.soakNode);
|
||||
namePart = name.match(IS_STRING) ? ("[" + (name) + "]") : ("." + (name));
|
||||
return this.prototype + namePart;
|
||||
};
|
||||
|
@ -568,7 +568,7 @@
|
|||
IndexNode.prototype.children = ['index'];
|
||||
IndexNode.prototype.compileNode = function(o) {
|
||||
var idx, prefix;
|
||||
o.chainRoot.wrapped = o.chainRoot.wrapped || this.soakNode;
|
||||
o.chainRoot.wrapped || (o.chainRoot.wrapped = this.soakNode);
|
||||
idx = this.index.compile(o);
|
||||
prefix = this.proto ? '.prototype' : '';
|
||||
return "" + (prefix) + "[" + (idx) + "]";
|
||||
|
@ -637,7 +637,7 @@
|
|||
to = _b[1];
|
||||
idx = del(o, 'index');
|
||||
step = del(o, 'step');
|
||||
step = step && ("" + (idx) + " += " + (step.compile(o)));
|
||||
step && (step = ("" + (idx) + " += " + (step.compile(o))));
|
||||
return from <= to ? ("" + (idx) + " = " + (from) + "; " + (idx) + " <" + (this.equals) + " " + (to) + "; " + (step || ("" + (idx) + "++"))) : ("" + (idx) + " = " + (from) + "; " + (idx) + " >" + (this.equals) + " " + (to) + "; " + (step || ("" + (idx) + "--")));
|
||||
};
|
||||
RangeNode.prototype.compileArray = function(o) {
|
||||
|
@ -745,7 +745,7 @@
|
|||
exports.ArrayNode = (function() {
|
||||
ArrayNode = function(_b) {
|
||||
this.objects = _b;
|
||||
this.objects = this.objects || [];
|
||||
this.objects || (this.objects = []);
|
||||
this.compileSplatLiteral = function(o) {
|
||||
return SplatNode.compileSplattedArray.call(this, this.objects, o);
|
||||
};
|
||||
|
@ -782,7 +782,7 @@
|
|||
this.properties = _d;
|
||||
this.parent = _c;
|
||||
this.variable = _b;
|
||||
this.properties = this.properties || [];
|
||||
this.properties || (this.properties = []);
|
||||
this.returns = false;
|
||||
return this;
|
||||
};
|
||||
|
@ -832,8 +832,8 @@
|
|||
}
|
||||
if (func instanceof CodeNode && func.bound) {
|
||||
func.bound = false;
|
||||
constScope = constScope || new Scope(o.scope, constructor.body, constructor);
|
||||
me = me || constScope.freeVariable();
|
||||
constScope || (constScope = new Scope(o.scope, constructor.body, constructor));
|
||||
me || (me = constScope.freeVariable());
|
||||
pname = pvar.compile(o);
|
||||
if (constructor.body.empty()) {
|
||||
constructor.body.push(new ReturnNode(literal('this')));
|
||||
|
@ -982,8 +982,8 @@
|
|||
CodeNode = function(_b, _c, tag) {
|
||||
this.body = _c;
|
||||
this.params = _b;
|
||||
this.params = this.params || [];
|
||||
this.body = this.body || new Expressions();
|
||||
this.params || (this.params = []);
|
||||
this.body || (this.body = new Expressions());
|
||||
this.bound = tag === 'boundfunc';
|
||||
return this;
|
||||
};
|
||||
|
@ -1064,7 +1064,7 @@
|
|||
};
|
||||
CodeNode.prototype.toString = function(idt) {
|
||||
var _b, _c, _d, _e, child, children;
|
||||
idt = idt || '';
|
||||
idt || (idt = '');
|
||||
children = (function() {
|
||||
_b = []; _d = this.collectChildren();
|
||||
for (_c = 0, _e = _d.length; _c < _e; _c++) {
|
||||
|
@ -1314,7 +1314,7 @@
|
|||
if (this.operator === '?=') {
|
||||
return ("" + (first) + " = " + (ExistenceNode.compileTest(o, literal(firstVar))[0]) + " ? " + (firstVar) + " : " + (second));
|
||||
}
|
||||
return "" + (first) + " = " + (firstVar) + " " + (this.operator.substr(0, 2)) + " " + (second);
|
||||
return "" + (first) + " " + (this.operator.substr(0, 2)) + " (" + (firstVar) + " = " + (second) + ")";
|
||||
};
|
||||
OpNode.prototype.compileExistence = function(o) {
|
||||
var _b, ref, test;
|
||||
|
@ -1495,7 +1495,7 @@
|
|||
this.index = _d;
|
||||
this.name = _c;
|
||||
this.body = _b;
|
||||
this.index = this.index || null;
|
||||
this.index || (this.index = null);
|
||||
this.source = source.source;
|
||||
this.guard = source.guard;
|
||||
this.step = source.step;
|
||||
|
@ -1635,7 +1635,7 @@
|
|||
this.tags = _d;
|
||||
this.body = _c;
|
||||
this.condition = _b;
|
||||
this.tags = this.tags || {};
|
||||
this.tags || (this.tags = {});
|
||||
if (this.tags.invert) {
|
||||
this.condition = new OpNode('!', new ParentheticalNode(this.condition));
|
||||
}
|
||||
|
@ -1700,7 +1700,7 @@
|
|||
return this;
|
||||
};
|
||||
IfNode.prototype.isStatement = function(o) {
|
||||
return this.statement = this.statement || (!!((o && o.top) || this.tags.statement || this.bodyNode().isStatement(o) || (this.elseBody && this.elseBodyNode().isStatement(o))));
|
||||
return this.statement || (this.statement = (!!((o && o.top) || this.tags.statement || this.bodyNode().isStatement(o) || (this.elseBody && this.elseBodyNode().isStatement(o)))));
|
||||
};
|
||||
IfNode.prototype.compileCondition = function(o) {
|
||||
var _b, _c, _d, _e, cond, conditions;
|
||||
|
@ -1722,8 +1722,8 @@
|
|||
};
|
||||
IfNode.prototype.makeReturn = function() {
|
||||
if (this.isStatement()) {
|
||||
this.body = this.body && this.ensureExpressions(this.body.makeReturn());
|
||||
this.elseBody = this.elseBody && this.ensureExpressions(this.elseBody.makeReturn());
|
||||
this.body && (this.body = this.ensureExpressions(this.body.makeReturn()));
|
||||
this.elseBody && (this.elseBody = this.ensureExpressions(this.elseBody.makeReturn()));
|
||||
return this;
|
||||
} else {
|
||||
return new ReturnNode(this);
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
var match;
|
||||
match = longFlag.match(OPTIONAL);
|
||||
longFlag = longFlag.match(LONG_FLAG)[1];
|
||||
options = options || {};
|
||||
options || (options = {});
|
||||
return {
|
||||
name: longFlag.substr(2),
|
||||
shortFlag: shortFlag,
|
||||
|
|
|
@ -264,7 +264,7 @@
|
|||
_f = pair;
|
||||
open = _f[0];
|
||||
close = _f[1];
|
||||
levels[open] = levels[open] || 0;
|
||||
levels[open] || (levels[open] = 0);
|
||||
if (token[0] === open) {
|
||||
if (levels[open] === 0) {
|
||||
openLine[open] = token[2];
|
||||
|
|
|
@ -1121,7 +1121,7 @@ exports.OpNode = class OpNode extends BaseNode
|
|||
second = "(#{second})" if @second instanceof OpNode
|
||||
o.scope.find(first) if first.match(IDENTIFIER)
|
||||
return "#{first} = #{ ExistenceNode.compileTest(o, literal(firstVar))[0] } ? #{firstVar} : #{second}" if @operator is '?='
|
||||
"#{first} = #{firstVar} #{ @operator.substr(0, 2) } #{second}"
|
||||
"#{first} #{ @operator.substr(0, 2) } (#{firstVar} = #{second})"
|
||||
|
||||
# If this is an existence operator, we delegate to `ExistenceNode.compileTest`
|
||||
# to give us the safe references for the variables.
|
||||
|
|
Loading…
Add table
Reference in a new issue