Commit 1c7a8e62 authored by Rasmus Villemoes's avatar Rasmus Villemoes Committed by Linus Torvalds

lib/vsprintf.c: help gcc make number() smaller

One consequence of the reorganization of struct printf_spec to make
field_width 24 bits was that number() gained about 180 bytes.  Since
spec is never passed to other functions, we can help gcc make number()
lose most of that extra weight by using local variables for the field
width and precision.
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Joe Perches <joe@perches.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Maurizio Lombardi <mlombard@redhat.com>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d0484193
...@@ -401,6 +401,8 @@ char *number(char *buf, char *end, unsigned long long num, ...@@ -401,6 +401,8 @@ char *number(char *buf, char *end, unsigned long long num,
int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10); int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10);
int i; int i;
bool is_zero = num == 0LL; bool is_zero = num == 0LL;
int field_width = spec.field_width;
int precision = spec.precision;
BUILD_BUG_ON(sizeof(struct printf_spec) != 8); BUILD_BUG_ON(sizeof(struct printf_spec) != 8);
...@@ -414,20 +416,20 @@ char *number(char *buf, char *end, unsigned long long num, ...@@ -414,20 +416,20 @@ char *number(char *buf, char *end, unsigned long long num,
if ((signed long long)num < 0) { if ((signed long long)num < 0) {
sign = '-'; sign = '-';
num = -(signed long long)num; num = -(signed long long)num;
spec.field_width--; field_width--;
} else if (spec.flags & PLUS) { } else if (spec.flags & PLUS) {
sign = '+'; sign = '+';
spec.field_width--; field_width--;
} else if (spec.flags & SPACE) { } else if (spec.flags & SPACE) {
sign = ' '; sign = ' ';
spec.field_width--; field_width--;
} }
} }
if (need_pfx) { if (need_pfx) {
if (spec.base == 16) if (spec.base == 16)
spec.field_width -= 2; field_width -= 2;
else if (!is_zero) else if (!is_zero)
spec.field_width--; field_width--;
} }
/* generate full string in tmp[], in reverse order */ /* generate full string in tmp[], in reverse order */
...@@ -449,12 +451,12 @@ char *number(char *buf, char *end, unsigned long long num, ...@@ -449,12 +451,12 @@ char *number(char *buf, char *end, unsigned long long num,
} }
/* printing 100 using %2d gives "100", not "00" */ /* printing 100 using %2d gives "100", not "00" */
if (i > spec.precision) if (i > precision)
spec.precision = i; precision = i;
/* leading space padding */ /* leading space padding */
spec.field_width -= spec.precision; field_width -= precision;
if (!(spec.flags & (ZEROPAD | LEFT))) { if (!(spec.flags & (ZEROPAD | LEFT))) {
while (--spec.field_width >= 0) { while (--field_width >= 0) {
if (buf < end) if (buf < end)
*buf = ' '; *buf = ' ';
++buf; ++buf;
...@@ -483,14 +485,14 @@ char *number(char *buf, char *end, unsigned long long num, ...@@ -483,14 +485,14 @@ char *number(char *buf, char *end, unsigned long long num,
if (!(spec.flags & LEFT)) { if (!(spec.flags & LEFT)) {
char c = ' ' + (spec.flags & ZEROPAD); char c = ' ' + (spec.flags & ZEROPAD);
BUILD_BUG_ON(' ' + ZEROPAD != '0'); BUILD_BUG_ON(' ' + ZEROPAD != '0');
while (--spec.field_width >= 0) { while (--field_width >= 0) {
if (buf < end) if (buf < end)
*buf = c; *buf = c;
++buf; ++buf;
} }
} }
/* hmm even more zero padding? */ /* hmm even more zero padding? */
while (i <= --spec.precision) { while (i <= --precision) {
if (buf < end) if (buf < end)
*buf = '0'; *buf = '0';
++buf; ++buf;
...@@ -502,7 +504,7 @@ char *number(char *buf, char *end, unsigned long long num, ...@@ -502,7 +504,7 @@ char *number(char *buf, char *end, unsigned long long num,
++buf; ++buf;
} }
/* trailing space padding */ /* trailing space padding */
while (--spec.field_width >= 0) { while (--field_width >= 0) {
if (buf < end) if (buf < end)
*buf = ' '; *buf = ' ';
++buf; ++buf;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment