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-w32-0bf44d00a42dec70514c2e51926f4ca37b4b2367.tar.gz
busybox-w32-0bf44d00a42dec70514c2e51926f4ca37b4b2367.tar.bz2
busybox-w32-0bf44d00a42dec70514c2e51926f4ca37b4b2367.zip
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)
48 return strncpy(dst, src, IFNAMSIZ); 48 return strncpy(dst, src, IFNAMSIZ);
49} 49}
50 50
51/* Convert unsigned long long value into compact 4-char
52 * representation. Examples: "1234", "1.2k", " 27M", "123T"
53 * String is not terminated (buf[4] is untouched) */
54void FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[5], const char *scale)
55{
56 const char *fmt;
57 char c;
58 unsigned v, u, idx = 0;
59
60 if (ul > 9999) { // do not scale if 9999 or less
61 ul *= 10;
62 do {
63 ul /= 1024;
64 idx++;
65 } while (ul >= 10000);
66 }
67 v = ul; // ullong divisions are expensive, avoid them
68
69 fmt = " 123456789";
70 u = v / 10;
71 v = v % 10;
72 if (!idx) {
73 // 9999 or less: use "1234" format
74 // u is value/10, v is last digit
75 c = buf[0] = " 123456789"[u/100];
76 if (c != ' ') fmt = "0123456789";
77 c = buf[1] = fmt[u/10%10];
78 if (c != ' ') fmt = "0123456789";
79 buf[2] = fmt[u%10];
80 buf[3] = "0123456789"[v];
81 } else {
82 // u is value, v is 1/10ths (allows for 9.2M format)
83 if (u >= 10) {
84 // value is >= 10: use "123M', " 12M" formats
85 c = buf[0] = " 123456789"[u/100];
86 if (c != ' ') fmt = "0123456789";
87 v = u % 10;
88 u = u / 10;
89 buf[1] = fmt[u%10];
90 } else {
91 // value is < 10: use "9.2M" format
92 buf[0] = "0123456789"[u];
93 buf[1] = '.';
94 }
95 buf[2] = "0123456789"[v];
96 buf[3] = scale[idx]; /* typically scale = " kmgt..." */
97 }
98}
99
100/* Convert unsigned long long value into compact 5-char representation.
101 * String is not terminated (buf[5] is untouched) */
102void FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[6], const char *scale)
103{
104 const char *fmt;
105 char c;
106 unsigned v, u, idx = 0;
107
108 if (ul > 99999) { // do not scale if 99999 or less
109 ul *= 10;
110 do {
111 ul /= 1024;
112 idx++;
113 } while (ul >= 100000);
114 }
115 v = ul; // ullong divisions are expensive, avoid them
116
117 fmt = " 123456789";
118 u = v / 10;
119 v = v % 10;
120 if (!idx) {
121 // 99999 or less: use "12345" format
122 // u is value/10, v is last digit
123 c = buf[0] = " 123456789"[u/1000];
124 if (c != ' ') fmt = "0123456789";
125 c = buf[1] = fmt[u/100%10];
126 if (c != ' ') fmt = "0123456789";
127 c = buf[2] = fmt[u/10%10];
128 if (c != ' ') fmt = "0123456789";
129 buf[3] = fmt[u%10];
130 buf[4] = "0123456789"[v];
131 } else {
132 // value has been scaled into 0..9999.9 range
133 // u is value, v is 1/10ths (allows for 92.1M format)
134 if (u >= 100) {
135 // value is >= 100: use "1234M', " 123M" formats
136 c = buf[0] = " 123456789"[u/1000];
137 if (c != ' ') fmt = "0123456789";
138 c = buf[1] = fmt[u/100%10];
139 if (c != ' ') fmt = "0123456789";
140 v = u % 10;
141 u = u / 10;
142 buf[2] = fmt[u%10];
143 } else {
144 // value is < 100: use "92.1M" format
145 c = buf[0] = " 123456789"[u/10];
146 if (c != ' ') fmt = "0123456789";
147 buf[1] = fmt[u%10];
148 buf[2] = '.';
149 }
150 buf[3] = "0123456789"[v];
151 buf[4] = scale[idx]; /* typically scale = " kmgt..." */
152 }
153}
154
155 51
156// Convert unsigned integer to ascii, writing into supplied buffer. 52// Convert unsigned integer to ascii, writing into supplied buffer.
157// A truncated result contains the first few digits of the result ala strncpy. 53// A truncated result contains the first few digits of the result ala strncpy.