Generate more efficient code for empty literals

Original patch by Wolfgang Kluge:

  797173f676
redux
David Majda 13 years ago
parent 4de3cc1716
commit 45c99f8f6b

@ -710,6 +710,14 @@ PEG.compiler.emitter = function(ast) {
literal: function(node, context) {
var length = node.value.length;
if (length === 0) {
return formatCode(
"${resultVar} = '';",
{ resultVar: resultVar(context.resultIndex) }
);
}
var testCode = length === 1
? formatCode(
"input.charCodeAt(pos) === ${valueCharCode}",

@ -280,15 +280,7 @@ PEG.parser = (function(){
if (result0 !== null) {
result1 = parse_literal();
if (result1 === null) {
if (input.substr(pos, 0) === "") {
result1 = "";
pos += 0;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\"\"");
}
}
result1 = '';
}
if (result1 !== null) {
@ -837,15 +829,7 @@ PEG.parser = (function(){
pos3 = pos;
result1 = parse_literal();
if (result1 === null) {
if (input.substr(pos, 0) === "") {
result1 = "";
pos += 0;
} else {
result1 = null;
if (reportFailures === 0) {
matchFailed("\"\"");
}
}
result1 = '';
}
if (result1 !== null) {

Loading…
Cancel
Save