Skip to content

Commit

Permalink
refactor: reorganize code to avoid doing more work than necessary
Browse files Browse the repository at this point in the history
For intance if `code` is `NL`, then we *already* know it is not a surrogate and
that it is a valid character.
  • Loading branch information
lddubeau committed Aug 31, 2018
1 parent a7495ac commit dcf84d0
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/saxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,26 +527,26 @@ class SaxesParser {
let code = chunk.charCodeAt(i);
let skip = 1;

if (code >= 0xD800 && code <= 0xDBFF) {
skip = 2;
code = 0x10000 + ((code - 0xD800) * 0x400) +
(chunk.charCodeAt(i + 1) - 0xDC00);
}

this.i = i + skip;

if (!isChar(code)) {
this.fail("disallowed character.");
}

if (code === NL) {
this.line++;
this.column = 0;
}
else {
if (code >= 0xD800 && code <= 0xDBFF) {
skip = 2;
code = 0x10000 + ((code - 0xD800) * 0x400) +
(chunk.charCodeAt(i + 1) - 0xDC00);
}

this.column += skip;

if (!isChar(code)) {
this.fail("disallowed character.");
}
}

this.i = i + skip;

return code;
}

Expand Down

0 comments on commit dcf84d0

Please sign in to comment.