Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of unescapeXML #125

Merged
merged 2 commits into from
Sep 30, 2018
Merged

Conversation

mogsie
Copy link
Contributor

@mogsie mogsie commented Sep 26, 2018

Half of #120 fixed by this change.

@@ -49,6 +49,9 @@ vows.describe('escape').addBatch({
'unescapes \'': function () {
assert.strictEqual(unescapeXML('''), '\'')
},
'leaves invalid entities alone': function () {
assert.strictEqual(unescapeXML('&foobar;'), '&foobar;')
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we throw instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my first inclination, and my first implementation, but I didn't want to break backwards compatibility, so I decided to write a test that verified that the behaviour didn't change. If anything, that might be better to put in a different PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds sane :) good candidate for release 3.0

@mogsie mogsie mentioned this pull request Sep 28, 2018
Erik Mogensen added 2 commits September 28, 2018 15:10
Invalid entities are passed through silently, meaning that
"<a>&foobar;</a>" is allowed, even though it technically isn't valid
XML.  In order to preserve backwards compatibility, this test has been
added to avoid changing this behaviour.
The original replace function uses a regular expression to find
expressions to parse.  It is more efficient to use the indexOf to find
the first matching '&' character and then the matching ';' character.

Fixes half of xmppjs#120.
@sonnyp
Copy link
Member

sonnyp commented Sep 29, 2018

parsers suite

before: ltx x 817,222 ops/sec ±1.94% (88 runs sampled)
after: ltx x 1,098,104 ops/sec ±0.87% (95 runs sampled)

Node.js v10.11.0 - Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz

@sonnyp sonnyp merged commit 2690f7c into xmppjs:master Sep 30, 2018
@mogsie mogsie deleted the performance-escape branch September 30, 2018 18:23
@sonnyp
Copy link
Member

sonnyp commented Oct 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants