Re: [RFC][PATCH 2/4] break out unit selection from string_get_size()

From: H. Peter Anvin
Date: Fri Sep 30 2011 - 14:54:43 EST


On 09/30/2011 11:02 AM, Dave Hansen wrote:
> string_get_size() can really only print things in a single
> format. You're always stuck with a space, and it will
> always zero-pad the decimal places:
>
> 4.00 KiB
> 40.0 KiB
> 400 KiB
>
> Printing page sizes in decimal KiB does not make much sense
> since they are always nice powers of two. But,
> string_get_size() does have some nice code for selecting
> the right units and doing the division.
>
> This breaks that nice code out so that we can reuse it.
> find_size_units() is a bit of a funky function since it has
> so many outputs. I don't think it's _too_ crazy though.
>
> Signed-off-by: Dave Hansen <dave@xxxxxxxxxxxxxxxxxx>

For powers of two, wouldn't it make a lot more sense to just do ilog2()
to get the power of two and then the moral equivalent of:

sprintf("%u %s", 1 << (pw2 % 10), units_str[pw2 / 10]);

-hpa
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/