Skip to content

Commit 9b479bc

Browse files
Tom Atkinsondarrachequesne
Tom Atkinson
authored andcommitted
[perf] Split try catch into separate function (#40)
1 parent 26699fa commit 9b479bc

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

index.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,22 @@ function decodeString(str) {
322322

323323
// look up json data
324324
if (str.charAt(++i)) {
325-
try {
326-
p.data = json.parse(str.substr(i));
327-
} catch(e){
328-
return error();
329-
}
325+
p = tryParse(p, str.substr(i));
330326
}
331327

332328
debug('decoded %s as %j', str, p);
333329
return p;
334330
}
335331

332+
function tryParse(p, str) {
333+
try {
334+
p.data = json.parse(str);
335+
} catch(e){
336+
return error();
337+
}
338+
return p;
339+
};
340+
336341
/**
337342
* Deallocates a parser's resources
338343
*

0 commit comments

Comments
 (0)