Skip to content

Commit 58004d8

Browse files
committed
Improve performance parsing other long packets
1 parent b774c2b commit 58004d8

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,9 @@ function decodeString(str) {
286286

287287
// look up attachments if type binary
288288
if (exports.BINARY_EVENT === p.type || exports.BINARY_ACK === p.type) {
289-
var buf = '';
290-
while (str.charAt(++i) !== '-') {
291-
buf += str.charAt(i);
292-
if (i == str.length) break;
293-
}
289+
var start = i + 1;
290+
while (str.charAt(++i) !== '-' && i != str.length) {}
291+
var buf = str.substring(start, i);
294292
if (buf != Number(buf) || str.charAt(i) !== '-') {
295293
throw new Error('Illegal attachments');
296294
}
@@ -299,13 +297,14 @@ function decodeString(str) {
299297

300298
// look up namespace (if any)
301299
if ('/' === str.charAt(i + 1)) {
302-
p.nsp = '';
300+
var start = i + 1;
303301
while (++i) {
304302
var c = str.charAt(i);
305303
if (',' === c) break;
306304
p.nsp += c;
307305
if (i === str.length) break;
308306
}
307+
p.nsp = str.substring(start, i);
309308
} else {
310309
p.nsp = '/';
311310
}

0 commit comments

Comments
 (0)