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

seq: Removed zero-padding of string when parsing with parse_exponent_no_decimal #6185

Merged
merged 5 commits into from
Apr 8, 2024
Merged

Conversation

maxer137
Copy link
Contributor

@maxer137 maxer137 commented Apr 3, 2024

This relates to #6182, but does not close the issue.
I looked into how seq parsed the width and found that we were padding the string with zeroes based on the exponent. This would mean that numbers with large exponents would generate a string with the same number of characters.

This PR removes the generation of the string.
Instead, the num_integral_digits is calculated directly. No new strings are generated now when parsing an exponent without decimals.

When exponent is greater than 0 we previously created a new string causing us to create a new string with a much larger size.
This would the get passed to the BigDecimal crate which would get stuck.
I had made the mistake of not running all the tests. This is indeed needed. However, you still need to add the exponent if it's positive for 0 numbers.
This way, 0 numbers (such as 0e+5) will be counted as having a width of 5.

This change also removes the memory allocation needed for the previous implementation. Where the string itself would be padded with zeros on the right side. Creating large numbers this method would cause large allocations in memory.

This does not seem to fix issue #6182.
Copy link

github-actions bot commented Apr 3, 2024

GNU testsuite comparison:

Skipping an intermittent issue tests/rm/rm1 (passes in this run but fails in the 'main' branch)

This adds the same fix applied to `parse_exponent_no_decimal`.
This way we don't need to create large strings
Copy link

github-actions bot commented Apr 5, 2024

GNU testsuite comparison:

Skip an intermittent issue tests/rm/rm1 (fails in this run but passes in the 'main' branch)

Copy link

github-actions bot commented Apr 6, 2024

GNU testsuite comparison:

Skip an intermittent issue tests/rm/rm1 (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)

@sylvestre sylvestre merged commit aeafabd into uutils:main Apr 8, 2024
63 of 64 checks passed
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.

2 participants