Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932369AbbEKTxN (ORCPT ); Mon, 11 May 2015 15:53:13 -0400 Received: from ns.horizon.com ([71.41.210.147]:38543 "HELO ns.horizon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1754041AbbEKTxL (ORCPT ); Mon, 11 May 2015 15:53:11 -0400 Date: 11 May 2015 15:53:10 -0400 Message-ID: <20150511195310.3608.qmail@ns.horizon.com> From: "George Spelvin" To: joe@perches.com, linux@rasmusvillemoes.dk Subject: [PATCH 1/2] lib/vsprintf.c: Simplify uuid_string() Cc: linux-kernel@vger.kernel.org, linux@horizon.com In-Reply-To: <20150511163230.14333.qmail@ns.horizon.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1944 Lines: 72 >From a53aa64b7b508d1f7cddbad556fb94f2c9c0191f Mon Sep 17 00:00:00 2001 From: George Spelvin Date: Mon, 11 May 2015 13:05:55 -0400 Subject: [PATCH 1/2] lib/vsprintf.c: Simplify uuid_string() Rather than have a second pass to upcase the buffer, just make the hex lookup table variable. I suspect it's a speedup, but since this is not hot code, the important part is that it shrinks the function from 332 to 256 bytes. Signed-off-by: George Spelvin --- With apologies for the un-compilable intermediate state of the draft. lib/vsprintf.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 452e4a16..4c4f9055 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1270,21 +1270,23 @@ char *uuid_string(char *buf, char *end, const u8 *addr, static const u8 be[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; static const u8 le[16] = {3,2,1,0,5,4,7,6,8,9,10,11,12,13,14,15}; const u8 *index = be; - bool uc = false; + const char *hex = hex_asc; switch (*(++fmt)) { case 'L': - uc = true; /* fall-through */ + hex = hex_asc_upper; /* fall-through */ case 'l': index = le; break; case 'B': - uc = true; + hex = hex_asc_upper; break; } for (i = 0; i < 16; i++) { - p = hex_byte_pack(p, addr[index[i]]); + u8 byte = addr[index[i]]; + *p++ = hex[byte >> 4]; + *p++ = hex[byte & 0x0f]; switch (i) { case 3: case 5: @@ -1297,13 +1299,6 @@ char *uuid_string(char *buf, char *end, const u8 *addr, *p = 0; - if (uc) { - p = uuid; - do { - *p = toupper(*p); - } while (*(++p)); - } - return string(buf, end, uuid, spec); } -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/