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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxx.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@xxxxxxxxx";> email@xxxxxxxxx </a>


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]