Skip to content

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

Merged
Vexu merged 1 commit into
masterfrom
unknown repository
May 10, 2023
Merged

Add std.fmt.parseIntSizeSuffix and use for --maxrss#14976
Vexu merged 1 commit into
masterfrom
unknown repository

Conversation

@ghost

Copy link
Copy Markdown

Fixes#14955

Comment threadlib/std/fmt.zig
}
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
Copy Markdown
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
Copy Markdown
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.

Comment threadlib/std/fmt.zig
Comment threadlib/std/fmt.zig Outdated
Comment threadlib/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
Copy Markdown
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
Copy Markdown
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.

Comment threadlib/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
Copy Markdown
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
Copy Markdown
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:masterMay 10, 2023
@ghost
ghost deleted the parse-int-size-suffix branch May 10, 2023 14:03
Sign up for freeto 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

@matu3ba@Vexu