From 6f510a033654a590fe3e5cc5719abac4544aa25a Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 19 Mar 2010 10:12:35 +0100 Subject: [PATCH] The cache does not remember match length but next position after the match. This leads to simpler and faster code because it avoids one addition and subtraction. --- lib/compiler.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index fcb7782..2931516 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -267,7 +267,7 @@ PEG.Grammar.Rule.prototype.compile = function() { " this._cache[${name|string}] = this._cache[${name|string}] || [];", " var cachedResult = this._cache[${name|string}][this._pos];", " if (cachedResult !== undefined) {", - " this._pos += cachedResult.length;", + " this._pos = cachedResult.nextPos;", " return cachedResult.result;", " }", " ", @@ -279,8 +279,8 @@ PEG.Grammar.Rule.prototype.compile = function() { " ${reportMatchFailureCode}", " ", " this._cache[${name|string}][pos] = {", - " length: this._pos - pos,", - " result: ${resultVar}", + " nextPos: this._pos,", + " result: ${resultVar}", " };", " return ${resultVar};", "};",