Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
perf($parse): removing references to Parser/Lexer from parsed express…
Browse files Browse the repository at this point in the history
…ions

This allows the parser and lexer objects to get GC-ed once the expression
is parsed.

Part of #8901
  • Loading branch information
jbedard authored and IgorMinar committed Sep 7, 2014
1 parent 1cfd49d commit 43c67cc
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/ng/parse.js
Expand Up @@ -258,7 +258,7 @@ Lexer.prototype = {
},

readIdent: function() {
var parser = this;
var expression = this.text;

var ident = '';
var start = this.index;
Expand Down Expand Up @@ -317,13 +317,13 @@ Lexer.prototype = {
token.fn = fn;
token.constant = true;
} else {
var getter = getterFn(ident, this.options, this.text);
var getter = getterFn(ident, this.options, expression);
// TODO(perf): consider exposing the getter reference
token.fn = extend(function $parsePathGetter(self, locals) {
return getter(self, locals);
}, {
assign: function(self, value) {
return setter(self, ident, value, parser.text);
return setter(self, ident, value, expression);
}
});
}
Expand Down Expand Up @@ -686,23 +686,23 @@ Parser.prototype = {
},

fieldAccess: function(object) {
var parser = this;
var expression = this.text;
var field = this.expect().text;
var getter = getterFn(field, this.options, this.text);
var getter = getterFn(field, this.options, expression);

return extend(function $parseFieldAccess(scope, locals, self) {
return getter(self || object(scope, locals));
}, {
assign: function(scope, value, locals) {
var o = object(scope, locals);
if (!o) object.assign(scope, o = {});
return setter(o, field, value, parser.text);
return setter(o, field, value, expression);
}
});
},

objectIndex: function(obj) {
var parser = this;
var expression = this.text;

var indexFn = this.expression();
this.consume(']');
Expand All @@ -712,15 +712,15 @@ Parser.prototype = {
i = indexFn(self, locals),
v;

ensureSafeMemberName(i, parser.text);
ensureSafeMemberName(i, expression);
if (!o) return undefined;
v = ensureSafeObject(o[i], parser.text);
v = ensureSafeObject(o[i], expression);
return v;
}, {
assign: function(self, value, locals) {
var key = ensureSafeMemberName(indexFn(self, locals), parser.text);
var key = ensureSafeMemberName(indexFn(self, locals), expression);
// prevent overwriting of Function.constructor which would break ensureSafeObject check
var o = ensureSafeObject(obj(self, locals), parser.text);
var o = ensureSafeObject(obj(self, locals), expression);
if (!o) obj.assign(self, o = {});
return o[key] = value;
}
Expand Down

0 comments on commit 43c67cc

Please sign in to comment.