From b91a82f7859053dbc0dcf9277cbc227d6d27588d Mon Sep 17 00:00:00 2001 From: thegrandpoobah Date: Tue, 1 Feb 2011 11:45:21 -0500 Subject: [PATCH] Don't actually do stack push/pops where it was done for purity's sake. Instead reference the elements explicitly. This results in a minor speed win (~2% on FF) --- mustache.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/mustache.js b/mustache.js index 50ce7c8..e2a136c 100644 --- a/mustache.js +++ b/mustache.js @@ -344,18 +344,14 @@ var Mustache = function() { var result = this.stateMachine.simpleKeyName.call(this, parserContext, contextStack); if (result==='closeMustache') { - var tagKey = parserContext.stack.pop(); - var tag = parserContext.stack.pop(); + var tagKey = parserContext.stack[parserContext.stack.length-1], + tag = parserContext.stack[parserContext.stack.length-2]; if (tag.tagType==='unescapedVariable' && tag.subtype==='tripleMustache') { - parserContext.stack.push({tagType:'unescapedVariable'}); - parserContext.stack.push(tagKey); + parserContext.stack[parserContext.stack.length-2] = {tagType:'unescapedVariable'}; return 'expectClosingMustache'; } else { - parserContext.stack.push(tag); - parserContext.stack.push(tagKey); - return 'closeMustache'; } } else if (result==='simpleKeyName') { @@ -389,7 +385,7 @@ var Mustache = function() { } else if (parserContext.token==='='){ throw new ParserException('Syntax error in Set Delimiter tag'); } else { - parserContext.stack.push(parserContext.stack.pop() + parserContext.token); + parserContext.stack[parserContext.stack.length-1] += parserContext.token; return 'setDelimiterStartOrWhitespace'; } @@ -411,7 +407,7 @@ var Mustache = function() { } else if (this.isWhitespace(parserContext.token)) { throw new ParserException('Syntax error in Set Delimiter tag'); } else { - parserContext.stack.push(parserContext.stack.pop() + parserContext.token); + parserContext.stack[parserContext.stack.length-1] += parserContext.token; return 'setDelimiterEndOrEqualSign'; }