-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Added fast path for Int and UInt #923
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -863,6 +863,10 @@ extension TestNSJSONSerialization { | |
("test_nested_array", test_nested_array), | ||
("test_nested_dictionary", test_nested_dictionary), | ||
("test_serialize_number", test_serialize_number), | ||
("test_serialize_IntMax", test_serialize_IntMax), | ||
("test_serialize_IntMin", test_serialize_IntMin), | ||
("test_serialize_UIntMax", test_serialize_UIntMax), | ||
("test_serialize_UIntMin", test_serialize_UIntMin), | ||
("test_serialize_stringEscaping", test_serialize_stringEscaping), | ||
("test_jsonReadingOffTheEndOfBuffers", test_jsonReadingOffTheEndOfBuffers), | ||
("test_jsonObjectToOutputStreamBuffer", test_jsonObjectToOutputStreamBuffer), | ||
|
@@ -1054,6 +1058,26 @@ extension TestNSJSONSerialization { | |
XCTAssertEqual(try trySerialize(json), "[false,true]") | ||
} | ||
|
||
func test_serialize_IntMax() { | ||
let json: [Any] = [Int.max] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Documentation:
So I think this will break on 32-bit platforms. We should construct the string we're asserting against using the same constant, I think. The same applies for the tests which use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for finding that, I've updated the tests to compare against a string representation of the |
||
XCTAssertEqual(try trySerialize(json), "[\(Int.max)]") | ||
} | ||
|
||
func test_serialize_IntMin() { | ||
let json: [Any] = [Int.min] | ||
XCTAssertEqual(try trySerialize(json), "[\(Int.min)]") | ||
} | ||
|
||
func test_serialize_UIntMax() { | ||
let json: [Any] = [UInt.max] | ||
XCTAssertEqual(try trySerialize(json), "[\(UInt.max)]") | ||
} | ||
|
||
func test_serialize_UIntMin() { | ||
let json: [Any] = [UInt.min] | ||
XCTAssertEqual(try trySerialize(json), "[\(UInt.min)]") | ||
} | ||
|
||
func test_serialize_stringEscaping() { | ||
var json = ["foo"] | ||
XCTAssertEqual(try trySerialize(json), "[\"foo\"]") | ||
|
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.
Though the loops where we walk backwards are not exactly identical in the two functions, I am wondering if we can still refactor them into a single function.
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 for the feedback, it is possible to refactor them into a single function however both Ian and myself felt the code looked more complicated and required a little more work in terms of casting and such, so I've omitted it for now.