aboutsummaryrefslogtreecommitdiff
path: root/libbb/xfuncs.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-10-13 01:25:09 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-10-13 01:25:09 +0200
commit0bf44d00a42dec70514c2e51926f4ca37b4b2367 (patch)
treebe01fbf44da8040c5ef271e0d0bba147ce0c525e /libbb/xfuncs.c
parent76ace254e171ee9ca7a13f36335ccad9cc6ae6e1 (diff)
downloadbusybox-0bf44d00a42dec70514c2e51926f4ca37b4b2367.tar.gz
libbb/human_readable.c: shrink; and reduce bss usage
also, move smart_ulltoaN there and comment usage locations function old new delta static.unit_chars 7 9 +2 utoa_to_buf 110 108 -2 make_human_readable_str 262 258 -4 fallbackSort 1723 1719 -4 static.fmt 97 92 -5 static.fmt_tenths 10 - -10 static.str 21 4 -17 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/5 up/down: 2/-42) Total: -40 bytes text data bss dec hex filename 820981 453 6932 828366 ca3ce busybox_old 820968 453 6916 828337 ca3b1 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/xfuncs.c')
-rw-r--r--libbb/xfuncs.c104
1 files changed, 0 insertions, 104 deletions
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index a86efc298..aa0812914 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -48,110 +48,6 @@ char* FAST_FUNC strncpy_IFNAMSIZ(char *dst, const char *src)
return strncpy(dst, src, IFNAMSIZ);
}
-/* Convert unsigned long long value into compact 4-char
- * representation. Examples: "1234", "1.2k", " 27M", "123T"
- * String is not terminated (buf[4] is untouched) */
-void FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[5], const char *scale)
-{
- const char *fmt;
- char c;
- 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";
- 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[u/10%10];
- if (c != ' ') fmt = "0123456789";
- buf[2] = fmt[u%10];
- buf[3] = "0123456789"[v];
- } else {
- // 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";
- 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];
- buf[3] = scale[idx]; /* typically scale = " kmgt..." */
- }
-}
-
-/* Convert unsigned long long value into compact 5-char representation.
- * String is not terminated (buf[5] is untouched) */
-void FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[6], const char *scale)
-{
- const char *fmt;
- char c;
- unsigned v, u, idx = 0;
-
- if (ul > 99999) { // do not scale if 99999 or less
- ul *= 10;
- do {
- ul /= 1024;
- idx++;
- } while (ul >= 100000);
- }
- v = ul; // ullong divisions are expensive, avoid them
-
- fmt = " 123456789";
- u = v / 10;
- v = v % 10;
- if (!idx) {
- // 99999 or less: use "12345" format
- // u is value/10, v is last digit
- c = buf[0] = " 123456789"[u/1000];
- if (c != ' ') fmt = "0123456789";
- c = buf[1] = fmt[u/100%10];
- if (c != ' ') fmt = "0123456789";
- c = buf[2] = fmt[u/10%10];
- if (c != ' ') fmt = "0123456789";
- buf[3] = fmt[u%10];
- buf[4] = "0123456789"[v];
- } else {
- // value has been scaled into 0..9999.9 range
- // u is value, v is 1/10ths (allows for 92.1M format)
- if (u >= 100) {
- // value is >= 100: use "1234M', " 123M" formats
- c = buf[0] = " 123456789"[u/1000];
- if (c != ' ') fmt = "0123456789";
- c = buf[1] = fmt[u/100%10];
- if (c != ' ') fmt = "0123456789";
- v = u % 10;
- u = u / 10;
- buf[2] = fmt[u%10];
- } else {
- // value is < 100: use "92.1M" format
- c = buf[0] = " 123456789"[u/10];
- if (c != ' ') fmt = "0123456789";
- buf[1] = fmt[u%10];
- buf[2] = '.';
- }
- buf[3] = "0123456789"[v];
- buf[4] = scale[idx]; /* typically scale = " kmgt..." */
- }
-}
-
// Convert unsigned integer to ascii, writing into supplied buffer.
// A truncated result contains the first few digits of the result ala strncpy.