Skip to content

Commit

Permalink
Improve performance parsing other long packets
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaller committed May 7, 2020
1 parent b774c2b commit 58004d8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions index.js
Expand Up @@ -286,11 +286,9 @@ function decodeString(str) {

// look up attachments if type binary
if (exports.BINARY_EVENT === p.type || exports.BINARY_ACK === p.type) {
var buf = '';
while (str.charAt(++i) !== '-') {
buf += str.charAt(i);
if (i == str.length) break;
}
var start = i + 1;
while (str.charAt(++i) !== '-' && i != str.length) {}
var buf = str.substring(start, i);
if (buf != Number(buf) || str.charAt(i) !== '-') {
throw new Error('Illegal attachments');
}
Expand All @@ -299,13 +297,14 @@ function decodeString(str) {

// look up namespace (if any)
if ('/' === str.charAt(i + 1)) {
p.nsp = '';
var start = i + 1;
while (++i) {
var c = str.charAt(i);
if (',' === c) break;
p.nsp += c;
if (i === str.length) break;
}
p.nsp = str.substring(start, i);
} else {
p.nsp = '/';
}
Expand Down

0 comments on commit 58004d8

Please sign in to comment.