From c7b8c3b92e341b94fc0f2d0b399a3bfd5ec6a2e7 Mon Sep 17 00:00:00 2001 From: Louis-Dominique Dubeau Date: Tue, 14 Aug 2018 19:10:00 -0400 Subject: [PATCH] perf: simplify the skip functions --- lib/saxes.js | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/lib/saxes.js b/lib/saxes.js index 924419b6..d6151fdc 100644 --- a/lib/saxes.js +++ b/lib/saxes.js @@ -572,21 +572,14 @@ class SaxesParser { */ skipWhile(chunkState, test) { const { limit } = chunkState; - let c; - // eslint-disable-next-line no-constant-condition - while (true) { - if (chunkState.i >= limit) { - c = undefined; - break; - } - - c = this.getCode(chunkState); + while (chunkState.i < limit) { + const c = this.getCode(chunkState); if (!test(c)) { - break; + return c; } } - return c; + return undefined; } /** @@ -601,21 +594,14 @@ class SaxesParser { */ skipWhitespace(chunkState) { const { limit } = chunkState; - let c; - // eslint-disable-next-line no-constant-condition - while (true) { - if (chunkState.i >= limit) { - c = undefined; - break; - } - - c = this.getCode(chunkState); + while (chunkState.i < limit) { + const c = this.getCode(chunkState); if (!isS(c)) { - break; + return c; } } - return c; + return undefined; }