-
Notifications
You must be signed in to change notification settings - Fork 1.2k
JSONSerialization: Improve number parsing for JSON #2980
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
Conversation
@swift-ci test |
7a310cd
to
c93c307
Compare
@swift-ci test |
ab86b7a
to
11685c3
Compare
@swift-ci test |
Sources/FoundationXML/XMLNode.swift
Outdated
@@ -14,7 +14,7 @@ import SwiftFoundation | |||
import Foundation | |||
#endif | |||
@_implementationOnly import CoreFoundation | |||
@_implementationOnly import CFXMLInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unintentionally added during commit?
@@ -13,7 +13,7 @@ import SwiftFoundation | |||
import Foundation | |||
#endif | |||
@_implementationOnly import CoreFoundation | |||
@_implementationOnly import CFXMLInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unintentionally added during commit?
c41803b
to
25c8f39
Compare
@swift-ci test |
var fractionExponent: Int? | ||
var exponentValue: Int? | ||
var negativeExponent = false | ||
var jsonString = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for moving your implementation into this parseNumber
function! 👍 I guess the only thing left from my side here, is the creation of jsonString
. In my point of view, we should only create the jsonString
at the very end of the number parsing based on the numbers arraySlice.
self.makeStringFast(self[numberStartIndex ..< self.readerIndex])
Appending to a String especially with Character(UnicodeScalar(ascii))
is, if I recall correctly, very slow.
25c8f39
to
c173435
Compare
@swift-ci test |
c173435
to
953b800
Compare
@swift-ci test |
953b800
to
7c223ec
Compare
@swift-ci test |
- Add _JSONNumber and _NSJSONNumber, an internal subclass of NSNumber, to provide lazy parsing of numbers at time of use. This avoids parsing numbers as Decimal when later bridged to Double/Float and vice-versa which has accuracy issues if converted from one to the other. - Add test cases for SR-7054 and SR-12244
7c223ec
to
a5887b7
Compare
@swift-ci test |
Closing older PRs after re-core of swift-corelibs-foundation on swift-foundation (#5001). |
This is a potential solution for SR-7054 and SR-12244 involving parsing JSON numbers and then later bridging them to
Decimal
or a floating point type and losing accuray compared to the original input. It will need to be updated after #2966 is merge but that will be minimal changes. The bridging should also be marginally faster as it doesnt need to create a 2ndNSNumber
for the equality check.Add _NSJSONNumber, an internal subclass of NSNumber to provide lazy
parsing of numbers at time of use. This avoids parsing numbers as
Decimal when later bridged to Double/Float and vice-versa which
has accuracy issues if converted from one to the other.
Add test cases for SR-7054 and SR-12244