From: Daniel Cousens Date: Sat, 15 Aug 2015 16:03:33 +0000 (+1000) Subject: avoid unnecessary hoisting X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=6ca21be3b1f3f48d17b473b6fccf40c72c21416f;p=buffer.git avoid unnecessary hoisting --- diff --git a/index.js b/index.js index 8d0a531..86c37bb 100644 --- a/index.js +++ b/index.js @@ -634,30 +634,20 @@ function decodeCodePointsArray (array) { function utf8Slice (buf, start, end) { end = Math.min(buf.length, end) - var firstByte - var secondByte - var thirdByte - var fourthByte - var bytesPerSequence - var tempCodePoint - var codePoint var res = [] - for (var i = start; i < end; i += bytesPerSequence) { - firstByte = buf[i] - codePoint = 0xFFFD - - if (firstByte > 0xEF) { - bytesPerSequence = 4 - } else if (firstByte > 0xDF) { - bytesPerSequence = 3 - } else if (firstByte > 0xBF) { - bytesPerSequence = 2 - } else { - bytesPerSequence = 1 - } + var i = start + while (i < end) { + var firstByte = buf[i] + var codePoint = 0xFFFD + var bytesPerSequence = (firstByte > 0xEF) ? 4 + : (firstByte > 0xDF) ? 3 + : (firstByte > 0xBF) ? 2 + : 1 if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint + switch (bytesPerSequence) { case 1: if (firstByte < 0x80) { @@ -707,6 +697,7 @@ function utf8Slice (buf, start, end) { } res.push(codePoint) + i += bytesPerSequence } return decodeCodePointsArray(res)