Skip to content

Add std.fmt.parseIntSizeSuffix and use for --maxrss #14976

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

Merged
merged 1 commit into from May 10, 2023
Merged

Add std.fmt.parseIntSizeSuffix and use for --maxrss #14976

merged 1 commit into from May 10, 2023

Conversation

ghost
Copy link

@ghost ghost commented Mar 17, 2023

Fixes #14955

}
if (without_i.len == 0) return error.InvalidCharacter;
const orders_of_magnitude: usize = switch (without_i[without_i.len - 1]) {
'k', 'K' => 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Multiple ways of doing this doesn't feel necessary, but not sure if hackability is more important in this case.

Copy link
Author

Choose a reason for hiding this comment

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

You mean the k/K? I did that because the SI and IEC use different capitalizations for the K, which I learned from reading the fmtIntSize docstrings.

lib/std/fmt.zig Outdated
if (mem.endsWith(u8, buf, "B")) without_b.len -= 1;
var without_i = without_b;
var base: usize = 1000;
if (mem.endsWith(u8, without_b, "i")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

sno/if (mem.endsWith(u8, without_b, "i")) {/if (mem.endsWith(u8, without_i, "i")) {

Copy link
Author

Choose a reason for hiding this comment

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

Wouldn't that be inconsistent with the first case? On line 1921, it checks the slice defined before without_b, so I figured that this line should check the slice defined before without_i.

lib/std/fmt.zig Outdated
var without_suffix = without_i;
if (orders_of_magnitude > 0) {
without_suffix.len -= 1;
} else if (without_i.len != without_b.len) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this check?

Copy link
Author

Choose a reason for hiding this comment

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

If there's an i but no magnitude prefix (see the "2iB" test case)

@Vexu Vexu merged commit 6d7bb25 into ziglang:master May 10, 2023
@ghost ghost deleted the parse-int-size-suffix branch May 10, 2023 14:03
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.

support G, M, GiB, MiB, GB, MB, etc. shorthands in --maxrss arg
2 participants