diff options
author | Denis Vlasenko | 2007-08-28 19:35:34 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-08-28 19:35:34 +0000 |
commit | b308d81e927d28cb0223378049defc133787727d (patch) | |
tree | cfbf133ee5fd42014250d233a7e4e3f0a76bf9ac /libbb/xfuncs.c | |
parent | 7d8de4d55dbc140ea0dc0131bb0647f9632cc7e9 (diff) | |
download | busybox-b308d81e927d28cb0223378049defc133787727d.zip busybox-b308d81e927d28cb0223378049defc133787727d.tar.gz |
top: use poll instead of select for waiting on one descriptor
smart_ulltoa5: make it more cryptic. -50 bytes.
function old new delta
passwd_main 1095 1103 +8
getNum 557 565 +8
buffer_fill_and_print 73 76 +3
udhcpc_main 2393 2395 +2
mkfs_minix_main 3071 3070 -1
dname_enc 377 373 -4
expmeta 480 472 -8
smart_ulltoa5 334 283 -51
top_main 911 815 -96
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/5 up/down: 21/-160) Total: -139 bytes
text data bss dec hex filename
770872 1063 10788 782723 bf183 busybox_old
770732 1063 10788 782583 bf0f7 busybox_unstripped
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r-- | libbb/xfuncs.c | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index fa9fc10..140c7bb 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -284,35 +284,44 @@ void smart_ulltoa5(unsigned long long ul, char buf[5]) { const char *fmt; char c; - unsigned v,idx = 0; - ul *= 10; - if (ul > 9999*10) { // do not scale if 9999 or less - while (ul >= 10000) { + unsigned v, u, idx = 0; + + if (ul > 9999) { // do not scale if 9999 or less + ul *= 10; + do { ul /= 1024; idx++; - } + } while (ul >= 10000); } v = ul; // ullong divisions are expensive, avoid them fmt = " 123456789"; - if (!idx) { // 9999 or less: use 1234 format - c = buf[0] = " 123456789"[v/10000]; + u = v / 10; + v = v % 10; + if (!idx) { + // 9999 or less: use "1234" format + // u is value/10, v is last digit + c = buf[0] = " 123456789"[u/100]; if (c != ' ') fmt = "0123456789"; - c = buf[1] = fmt[v/1000%10]; + c = buf[1] = fmt[u/10%10]; if (c != ' ') fmt = "0123456789"; - buf[2] = fmt[v/100%10]; - buf[3] = "0123456789"[v/10%10]; + buf[2] = fmt[u%10]; + buf[3] = "0123456789"[v]; } else { - if (v >= 10*10) { // scaled value is >=10: use 123M format - c = buf[0] = " 123456789"[v/1000]; + // u is value, v is 1/10ths (allows for 9.2M format) + if (u >= 10) { + // value is >= 10: use "123M', " 12M" formats + c = buf[0] = " 123456789"[u/100]; if (c != ' ') fmt = "0123456789"; - buf[1] = fmt[v/100%10]; - buf[2] = "0123456789"[v/10%10]; - } else { // scaled value is <10: use 1.2M format - buf[0] = "0123456789"[v/10]; + v = u % 10; + u = u / 10; + buf[1] = fmt[u%10]; + } else { + // value is < 10: use "9.2M" format + buf[0] = "0123456789"[u]; buf[1] = '.'; - buf[2] = "0123456789"[v%10]; } + buf[2] = "0123456789"[v]; // see http://en.wikipedia.org/wiki/Tera buf[3] = " kMGTPEZY"[idx]; } @@ -470,7 +479,8 @@ char *xasprintf(const char *format, ...) va_end(p); #endif - if (r < 0) bb_error_msg_and_die(bb_msg_memory_exhausted); + if (r < 0) + bb_error_msg_and_die(bb_msg_memory_exhausted); return string_ptr; } |