From dcf84d0c0871db94d211e8b5035546b4974e17c7 Mon Sep 17 00:00:00 2001 From: Louis-Dominique Dubeau Date: Fri, 31 Aug 2018 13:17:47 -0400 Subject: [PATCH] refactor: reorganize code to avoid doing more work than necessary For intance if `code` is `NL`, then we *already* know it is not a surrogate and that it is a valid character. --- lib/saxes.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/saxes.js b/lib/saxes.js index 2985798a..011dead6 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -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; }