Skip to content

Commit

Permalink
optimized simple escaped chars lookup
Browse files Browse the repository at this point in the history
Vitaly Puzrin committed Jul 7, 2014
1 parent e4aeff5 commit 284c019
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/js-yaml/loader.js
Original file line number Diff line number Diff line change
@@ -103,6 +103,13 @@ function simpleEscapeSequence(c) {
(c === 0x50/* P */) ? '\u2029' : '';
}

var simpleEscapeCheck = new Array(256); // integer, for fast access
var simpleEscapeMap = new Array(256);
for (var i = 0; i < 256; i++) {
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
simpleEscapeMap[i] = simpleEscapeSequence(i);
}


function State(input, options) {
this.input = input;
@@ -561,8 +568,8 @@ function readDoubleQuotedScalar(state, nodeIndent) {
skipSeparationSpace(state, false, nodeIndent);

//TODO: rework to inline fn with no type cast?
} else if ((tmpEsc = simpleEscapeSequence(ch)) !== '') {
state.result += tmpEsc;
} else if (ch < 256 && simpleEscapeCheck[ch]) {
state.result += simpleEscapeMap[ch];
state.position++;

} else if ((tmp = escapedHexLen(ch)) > 0) {

0 comments on commit 284c019

Please sign in to comment.