create node 'class' - improve v8 performance

This commit is contained in:
Alistair Braidwood 2012-12-21 08:23:38 +00:00 committed by Marijn Haverbeke
parent 2bad03e654
commit c8eb50fabe

View File

@ -881,14 +881,26 @@
// Start an AST node, attaching a start offset and optionally a // Start an AST node, attaching a start offset and optionally a
// `commentsBefore` property to it. // `commentsBefore` property to it.
var node_t = function(s) {
this.type=null;
this.start=tokStart;
this.end=null;
};
var node_loc_t = function(s) {
this.start=tokStartLoc;
this.end=null;
};
node_loc_t.prototype.source=sourceFile;
function startNode() { function startNode() {
var node = {type: null, start: tokStart, end: null}; var node = new node_t();
if (options.trackComments && tokCommentsBefore) { if (options.trackComments && tokCommentsBefore) {
node.commentsBefore = tokCommentsBefore; node.commentsBefore = tokCommentsBefore;
tokCommentsBefore = null; tokCommentsBefore = null;
} }
if (options.locations) if (options.locations)
node.loc = {start: tokStartLoc, end: null, source: sourceFile}; node.loc = new node_loc_t();
if (options.ranges) if (options.ranges)
node.range = [tokStart, 0]; node.range = [tokStart, 0];
return node; return node;
@ -900,13 +912,16 @@
// already been parsed. // already been parsed.
function startNodeFrom(other) { function startNodeFrom(other) {
var node = {type: null, start: other.start}; var node = new node_t();
node.start = other.start;
if (other.commentsBefore) { if (other.commentsBefore) {
node.commentsBefore = other.commentsBefore; node.commentsBefore = other.commentsBefore;
other.commentsBefore = null; other.commentsBefore = null;
} }
if (options.locations) if (options.locations) {
node.loc = {start: other.loc.start, end: null, source: other.loc.source}; node.loc = new node_loc_t();
node.loc.start = other.loc.start;//{start: other.loc.start, end: null, source: other.loc.source};
}
if (options.ranges) if (options.ranges)
node.range = [other.range[0], 0]; node.range = [other.range[0], 0];