From d3aff0c66a7d08184ca723a1e10ddc59c7e9f9b3 Mon Sep 17 00:00:00 2001 From: David Majda Date: Fri, 9 Sep 2011 19:45:22 +0200 Subject: [PATCH] Use |charAt| instead of |substr| when matching classes Speed impact ------------ Before: 131.36 kB/s After: 213.59 kB/s Difference: 62.59% Size impact ----------- Before: 1056976 b After: 1056976 b Difference: 0.00% (Measured by /tools/impact with Node.js v0.4.8 on x86_64 GNU/Linux.) Closes GH-49. --- src/emitter.js | 2 +- src/parser.js | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/emitter.js b/src/emitter.js index adc5d51..8ce1d89 100644 --- a/src/emitter.js +++ b/src/emitter.js @@ -753,7 +753,7 @@ PEG.compiler.emitter = function(ast) { } return formatCode( - "if (${regexp}.test(input.substr(pos))) {", + "if (${regexp}.test(input.charAt(pos))) {", " ${resultVar} = input.charAt(pos);", " pos++;", "} else {", diff --git a/src/parser.js b/src/parser.js index e16e0dd..7151295 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1123,7 +1123,7 @@ PEG.parser = (function(){ var pos0; - if (/^[^{}]/.test(input.substr(pos))) { + if (/^[^{}]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else { @@ -3023,7 +3023,7 @@ PEG.parser = (function(){ var pos0; - if (/^[0-9]/.test(input.substr(pos))) { + if (/^[0-9]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else { @@ -3054,7 +3054,7 @@ PEG.parser = (function(){ var pos0; - if (/^[0-9a-fA-F]/.test(input.substr(pos))) { + if (/^[0-9a-fA-F]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else { @@ -3112,7 +3112,7 @@ PEG.parser = (function(){ var pos0; - if (/^[a-z]/.test(input.substr(pos))) { + if (/^[a-z]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else { @@ -3143,7 +3143,7 @@ PEG.parser = (function(){ var pos0; - if (/^[A-Z]/.test(input.substr(pos))) { + if (/^[A-Z]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else { @@ -3571,7 +3571,7 @@ PEG.parser = (function(){ var pos0; - if (/^[\n\r\u2028\u2029]/.test(input.substr(pos))) { + if (/^[\n\r\u2028\u2029]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else { @@ -3602,7 +3602,7 @@ PEG.parser = (function(){ var pos0; reportFailures++; - if (/^[ \xA0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]/.test(input.substr(pos))) { + if (/^[ \xA0\uFEFF\u1680\u180E\u2000-\u200A\u202F\u205F\u3000]/.test(input.charAt(pos))) { result0 = input.charAt(pos); pos++; } else {