Replaced two-level rule cache with a one-level one.
This leads to simpler code and also speeds up the benchmark suite execution by 5,89 % on V8. Detailed results (benchmark suite totals): --------------------------------- Test # Before After --------------------------------- 1 24,70 kB/s 26,14 kB/s 2 24,49 kB/s 26,05 kB/s 3 24,67 kB/s 25,99 kB/s 4 24,65 kB/s 26,13 kB/s 5 24,71 kB/s 26,14 kB/s --------------------------------- Average 24,64 kB/s 26.10 kB/s --------------------------------- Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.7 Safari/533.2
This commit is contained in:
parent
74830d4f8f
commit
24d38f74b9
|
@ -394,8 +394,8 @@ PEG.Grammar.Rule.prototype.compile = function() {
|
|||
|
||||
return PEG.Compiler.formatCode(
|
||||
"result._parse_${name} = function(context) {",
|
||||
" this._cache[${name|string}] = this._cache[${name|string}] || [];",
|
||||
" var cachedResult = this._cache[${name|string}][this._pos];",
|
||||
" var cacheKey = ${name|string} + '@' + this._pos;",
|
||||
" var cachedResult = this._cache[cacheKey];",
|
||||
" if (cachedResult !== undefined) {",
|
||||
" this._pos = cachedResult.nextPos;",
|
||||
" return cachedResult.result;",
|
||||
|
@ -408,7 +408,7 @@ PEG.Grammar.Rule.prototype.compile = function() {
|
|||
" ${restoreReportMatchFailuresCode}",
|
||||
" ${reportMatchFailureCode}",
|
||||
" ",
|
||||
" this._cache[${name|string}][pos] = {",
|
||||
" this._cache[cacheKey] = {",
|
||||
" nextPos: this._pos,",
|
||||
" result: ${resultVar}",
|
||||
" };",
|
||||
|
|
Loading…
Reference in a new issue