Skip to content

Commit 25513a4

Browse files
mscdexrvagg
authored andcommitted
string_decoder: fix performance regression
This commit reverts the const usage introduced by 68a6abc because v8 currently cannot optimize functions that contain these uses of const (unsupported phi use of const variable). The performance difference in this case can be up to ~130% for non-ascii/binary string encodings. PR-URL: #5134 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 3955bc4 commit 25513a4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/string_decoder.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ StringDecoder.prototype.write = function(buffer) {
6969
var charReceived = this.charReceived;
7070
var surrogateSize = this.surrogateSize;
7171
var encoding = this.encoding;
72+
var charCode;
7273
// if our last write ended with an incomplete multibyte character
7374
while (charLength) {
7475
// determine how many remaining bytes this buffer has to offer for this char
@@ -96,7 +97,7 @@ StringDecoder.prototype.write = function(buffer) {
9697
charStr = charBuffer.toString(encoding, 0, charLength);
9798

9899
// CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
99-
const charCode = charStr.charCodeAt(charStr.length - 1);
100+
charCode = charStr.charCodeAt(charStr.length - 1);
100101
if (charCode >= 0xD800 && charCode <= 0xDBFF) {
101102
charLength += surrogateSize;
102103
charStr = '';
@@ -129,7 +130,7 @@ StringDecoder.prototype.write = function(buffer) {
129130
charStr += buffer.toString(encoding, 0, end);
130131

131132
end = charStr.length - 1;
132-
const charCode = charStr.charCodeAt(end);
133+
charCode = charStr.charCodeAt(end);
133134
// CESU-8: lead surrogate (D800-DBFF) is also the incomplete character
134135
if (charCode >= 0xD800 && charCode <= 0xDBFF) {
135136
charLength += surrogateSize;

0 commit comments

Comments
 (0)