numfmt & others: Dedup some code #11645
Merged
cakebaker merged 9 commits intouutils:mainfrom Apr 5, 2026
Merged
Conversation
|
GNU testsuite comparison: |
Merging this PR will degrade performance by 4.82%
Performance Changes
Comparing Footnotes
|
cakebaker
reviewed
Apr 5, 2026
src/uu/numfmt/src/units.rs
Outdated
| // For the full copyright and license information, please view the LICENSE | ||
| // file that was distributed with this source code. | ||
| use std::fmt; | ||
| use uucore::parser::parse_size::{IEC_BASES as IEC_BASES_U128, SI_BASES as SI_BASES_U128}; |
Contributor
There was a problem hiding this comment.
What's the reason for the renames?
cakebaker
reviewed
Apr 5, 2026
Comment on lines
+46
to
+62
| /// Index of this suffix in the base arrays, minus one. | ||
| /// `K` is 0, `M` is 1, ..., `Q` is 9. The associated base is | ||
| /// `BASES[self.index() + 1]`. | ||
| pub fn index(self) -> usize { | ||
| match self { | ||
| Self::K => 0, | ||
| Self::M => 1, | ||
| Self::G => 2, | ||
| Self::T => 3, | ||
| Self::P => 4, | ||
| Self::E => 5, | ||
| Self::Z => 6, | ||
| Self::Y => 7, | ||
| Self::R => 8, | ||
| Self::Q => 9, | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
This feels error prone, though currently I don't see a better solution :|
|
GNU testsuite comparison: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.