Skip to content

Commit b081a5d

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

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

index.js

+5-7
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,13 @@ 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;
306-
p.nsp += c;
307304
if (i === str.length) break;
308305
}
306+
p.nsp = str.substring(start, i);
309307
} else {
310308
p.nsp = '/';
311309
}

0 commit comments

Comments
 (0)