Skip to content

Commit

Permalink
[perf] Split try catch into separate function (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Atkinson authored and darrachequesne committed Oct 20, 2016
1 parent 26699fa commit 9b479bc
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,22 @@ function decodeString(str) {

// look up json data
if (str.charAt(++i)) {
try {
p.data = json.parse(str.substr(i));
} catch(e){
return error();
}
p = tryParse(p, str.substr(i));
}

debug('decoded %s as %j', str, p);
return p;
}

function tryParse(p, str) {
try {
p.data = json.parse(str);
} catch(e){
return error();
}
return p;
};

/**
* Deallocates a parser's resources
*
Expand Down

0 comments on commit 9b479bc

Please sign in to comment.