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

Issue with object with decimal value #1133

Merged

Conversation

anto-ac
Copy link
Collaborator

@anto-ac anto-ac commented Jun 17, 2020

See new tests added in JsonParserSpec. Most decimal values as values were not being parses correctly.

{"1": { "2": 200.25}}: was working
{"1": { "2": 20.25}}: wasn't working.

The method changed by @e-ivaldi is used in a lot of places, so @uglyog could you think of any unwanted effects?

Copy link
Member

@uglyog uglyog left a comment

Choose a reason for hiding this comment

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

I'm going to merge this and then update the change.

@@ -94,7 +94,7 @@ protected void skipWhitespace() {
}

private char[] allocate(char[] buffer, int size) {
char[] newBuffer = new char[Math.max(buffer.length * 2, size)];
Copy link
Member

Choose a reason for hiding this comment

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

The actual change I was trying to do should be:
buffer.length + Math.max(buffer.length, size)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah thank you, what's the rationale behind that?
I have mostly looked at it within the context of parsing the decimal numbers, where as long as the buffer is of the proper size everything's fine, and only checked all the tests were still good with it.

Copy link
Member

Choose a reason for hiding this comment

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

I've been trying to minimise the number of array allocations and copies for performance reasons. So start with 16 characters, and then double it if we need to extend. That way it should probably only happen once for numbers. But for large strings it will go from the base (128), 256, 512, 1024, etc.

Copy link
Member

Choose a reason for hiding this comment

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

For that case, we have parsed the first part of the number, so size is that number of digits, but there will be more after the ., so just expand the buffer to the next point as long as that is big enough.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for expanding on it

@uglyog uglyog merged commit 63f3df0 into pact-foundation:master Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants