Skip to content

Commit

Permalink
Merge pull request #369 from lovell/onclosetag-wrap-trycatch
Browse files Browse the repository at this point in the history
Allow V8 to optimise onclosetag function for ~2% performance gain
  • Loading branch information
Leonidas-from-XIV authored Mar 21, 2017
2 parents b5e351a + 5b83012 commit 2386f4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
19 changes: 11 additions & 8 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions src/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,13 @@ class exports.Parser extends events.EventEmitter

if @options.validator?
xpath = "/" + (node["#name"] for node in stack).concat(nodeName).join("/")
try
obj = @options.validator(xpath, s and s[nodeName], obj)
catch err
@emit "error", err
# Wrap try/catch with an inner function to allow V8 to optimise the containing function
# See https://github.com/Leonidas-from-XIV/node-xml2js/pull/369
do =>
try
obj = @options.validator(xpath, s and s[nodeName], obj)
catch err
@emit "error", err

# put children into <childkey> property and unfold chars if necessary
if @options.explicitChildren and not @options.mergeAttrs and typeof obj is 'object'
Expand Down

0 comments on commit 2386f4c

Please sign in to comment.