]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
lib/vsprintf.c: help gcc make number() smaller
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Sat, 16 Jan 2016 00:58:41 +0000 (16:58 -0800)
committerMaran Wilson <maran.wilson@oracle.com>
Wed, 15 Nov 2017 23:14:22 +0000 (15:14 -0800)
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: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Rasmus 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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 1c7a8e622e84c9164dd665f5ad4879eac71bdc1e)

Orabug: 26178769

Signed-off-by: Maran Wilson <maran.wilson@oracle.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
lib/vsprintf.c

index fc2be29a93720adaeda8029aba7c3ae67eafdd9b..0c4a13baa87b0b4448b2f2eb1e0b9a9db085ffba 100644 (file)
@@ -397,6 +397,8 @@ char *number(char *buf, char *end, unsigned long long num,
        int need_pfx = ((spec.flags & SPECIAL) && spec.base != 10);
        int i;
        bool is_zero = num == 0LL;
+       int field_width = spec.field_width;
+       int precision = spec.precision;
 
        BUILD_BUG_ON(sizeof(struct printf_spec) != 8);
 
@@ -410,20 +412,20 @@ char *number(char *buf, char *end, unsigned long long num,
                if ((signed long long)num < 0) {
                        sign = '-';
                        num = -(signed long long)num;
-                       spec.field_width--;
+                       field_width--;
                } else if (spec.flags & PLUS) {
                        sign = '+';
-                       spec.field_width--;
+                       field_width--;
                } else if (spec.flags & SPACE) {
                        sign = ' ';
-                       spec.field_width--;
+                       field_width--;
                }
        }
        if (need_pfx) {
                if (spec.base == 16)
-                       spec.field_width -= 2;
+                       field_width -= 2;
                else if (!is_zero)
-                       spec.field_width--;
+                       field_width--;
        }
 
        /* generate full string in tmp[], in reverse order */
@@ -445,12 +447,12 @@ char *number(char *buf, char *end, unsigned long long num,
        }
 
        /* printing 100 using %2d gives "100", not "00" */
-       if (i > spec.precision)
-               spec.precision = i;
+       if (i > precision)
+               precision = i;
        /* leading space padding */
-       spec.field_width -= spec.precision;
+       field_width -= precision;
        if (!(spec.flags & (ZEROPAD | LEFT))) {
-               while (--spec.field_width >= 0) {
+               while (--field_width >= 0) {
                        if (buf < end)
                                *buf = ' ';
                        ++buf;
@@ -479,14 +481,14 @@ char *number(char *buf, char *end, unsigned long long num,
        if (!(spec.flags & LEFT)) {
                char c = ' ' + (spec.flags & ZEROPAD);
                BUILD_BUG_ON(' ' + ZEROPAD != '0');
-               while (--spec.field_width >= 0) {
+               while (--field_width >= 0) {
                        if (buf < end)
                                *buf = c;
                        ++buf;
                }
        }
        /* hmm even more zero padding? */
-       while (i <= --spec.precision) {
+       while (i <= --precision) {
                if (buf < end)
                        *buf = '0';
                ++buf;
@@ -498,7 +500,7 @@ char *number(char *buf, char *end, unsigned long long num,
                ++buf;
        }
        /* trailing space padding */
-       while (--spec.field_width >= 0) {
+       while (--field_width >= 0) {
                if (buf < end)
                        *buf = ' ';
                ++buf;