From patchwork Sun Mar 7 01:10:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 47063 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 81B49B7067 for ; Sun, 7 Mar 2010 12:10:45 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753835Ab0CGBKR (ORCPT ); Sat, 6 Mar 2010 20:10:17 -0500 Received: from mail.perches.com ([173.55.12.10]:1488 "EHLO mail.perches.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753632Ab0CGBKQ (ORCPT ); Sat, 6 Mar 2010 20:10:16 -0500 Received: from [192.168.1.153] (new-host-3.home [192.168.1.153]) by mail.perches.com (Postfix) with ESMTP id 0651A24368; Sat, 6 Mar 2010 17:10:09 -0800 (PST) Subject: [PATCH] vsprintf.c: Reduce sizeof struct printf_spec from 24 to 8 bytes From: Joe Perches To: Linus Torvalds Cc: Andrew Morton , Nick Andrew , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , netdev@vger.kernel.org In-Reply-To: References: <20100304143837.af39845d.akpm@linux-foundation.org> <1267911399.849.39.camel@Joe-Laptop.home> <1267914654.849.81.camel@Joe-Laptop.home> <1267918554.849.89.camel@Joe-Laptop.home> Date: Sat, 06 Mar 2010 17:10:14 -0800 Message-ID: <1267924214.1937.12.camel@Joe-Laptop.home> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Sat, 2010-03-06 at 15:58 -0800, Linus Torvalds wrote: > And no, I guess we don't really need to make it 32-bit. Fitting in 64 bits > would already be a big improvement over what we have now. Reducing the size of struct printf_spec is a good thing because multiple instances are commonly passed on stack. It's possible for type to be u8 and field_width to be s8, but this is likely small enough for now. Signed-off-by: Joe Perches --- lib/vsprintf.c | 22 ++++++++++++---------- 1 files changed, 12 insertions(+), 10 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/lib/vsprintf.c b/lib/vsprintf.c index af4aaa6..fdee7f7 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -408,12 +408,12 @@ enum format_type { }; struct printf_spec { - enum format_type type; - int flags; /* flags to number() */ - int field_width; /* width of output field */ - int base; - int precision; /* # of digits/chars */ - int qualifier; + u16 type; + s16 field_width; /* width of output field */ + u8 flags; /* flags to number() */ + u8 base; + s8 precision; /* # of digits/chars */ + u8 qualifier; }; static char *number(char *buf, char *end, unsigned long long num, @@ -1333,7 +1333,7 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) break; case FORMAT_TYPE_NRCHARS: { - int qualifier = spec.qualifier; + u8 qualifier = spec.qualifier; if (qualifier == 'l') { long *ip = va_arg(args, long *); @@ -1619,7 +1619,7 @@ do { \ case FORMAT_TYPE_NRCHARS: { /* skip %n 's argument */ - int qualifier = spec.qualifier; + u8 qualifier = spec.qualifier; void *skip_arg; if (qualifier == 'l') skip_arg = va_arg(args, long *); @@ -1885,7 +1885,9 @@ int vsscanf(const char *buf, const char *fmt, va_list args) char *next; char digit; int num = 0; - int qualifier, base, field_width; + u8 qualifier; + u8 base; + s16 field_width; bool is_sign; while (*fmt && *str) { @@ -1963,7 +1965,7 @@ int vsscanf(const char *buf, const char *fmt, va_list args) { char *s = (char *)va_arg(args, char *); if (field_width == -1) - field_width = INT_MAX; + field_width = SHORT_MAX; /* first, skip leading white space in buffer */ str = skip_spaces(str);