From 9b479bcee657f7efe9ec4db617ae1b27d69da1e7 Mon Sep 17 00:00:00 2001 From: Tom Atkinson Date: Fri, 21 Oct 2016 01:07:30 +0200 Subject: [PATCH] [perf] Split try catch into separate function (#40) --- index.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 8e63394e5b..165a4a6f1c 100644 --- a/index.js +++ b/index.js @@ -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 *