Closed
Bug 509678
Opened 15 years ago
Closed 15 years ago
Performance improvement for built-in JSON parser
Categories
(Rhino Graveyard :: Core, enhancement)
Tracking
(Not tracked)
RESOLVED
FIXED
People
(Reporter: hannesw, Unassigned)
Details
Attachments
(4 files)
22.68 KB,
patch
|
Details | Diff | Splinter Review | |
28.47 KB,
patch
|
Details | Diff | Splinter Review | |
642 bytes,
patch
|
Details | Diff | Splinter Review | |
505 bytes,
patch
|
Details | Diff | Splinter Review |
The parser for the built-in JSON object is currently based on regular expressions (see bug 505211). This is a hand written parser that should be quite a bit faster. A few notes regarding numbers: I'm using java.lang.Double.valueOf() to parse numbers, as from empirical testing this does the right thing in most cases (except for leading zeroes, which I check for manually). Also, I removed the special handling for very large numbers using java.math.BigDecimal, so now 9999999999999999 is parsed as 10000000000000000 and 1.5e99999999 is parsed as positive Infinity. This matches the way numbers are parsed by the main Rhino parser, Spidermonkey, and V8, and I couln't find anything in the ES5 spec saying that JSON numbers should be parsed differently. I changed the unit test accordingly.
Reporter | ||
Comment 1•15 years ago
|
||
Comment 2•15 years ago
|
||
Reporter | ||
Comment 3•15 years ago
|
||
I committed the last patch plus a minor fix in two of the tests I added, and removed the JsonLexer class which isn't used anymore. Removing src/org/mozilla/javascript/json/JsonLexer.java; /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/json/JsonLexer.java,v <-- JsonLexer.java new revision: delete; previous revision: 1.1 done Checking in src/org/mozilla/javascript/json/JsonParser.java; /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/json/JsonParser.java,v <-- JsonParser.java new revision: 1.2; previous revision: 1.1 done Removing testsrc/org/mozilla/javascript/tests/json/JsonLexerTest.java; /cvsroot/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/json/JsonLexerTest.java,v <-- JsonLexerTest.java new revision: delete; previous revision: 1.1 done Checking in testsrc/org/mozilla/javascript/tests/json/JsonParserTest.java; /cvsroot/mozilla/js/rhino/testsrc/org/mozilla/javascript/tests/json/JsonParserTest.java,v <-- JsonParserTest.java new revision: 1.2; previous revision: 1.1 done
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Comment 4•15 years ago
|
||
Thanks so much for doing this!
Reporter | ||
Comment 6•15 years ago
|
||
Thanks Raphael, I committed your patch.
Comment 8•15 years ago
|
||
Thanks, Raphael, this fixes a regression in the unit test. Patch committed: Checking in src/org/mozilla/javascript/json/JsonParser.java; /cvsroot/mozilla/js/rhino/src/org/mozilla/javascript/json/JsonParser.java,v <-- JsonParser.java new revision: 1.5; previous revision: 1.4 done
You need to log in
before you can comment on or make changes to this bug.
Description
•