[PATCH v2 1/7] vsprintf: factorize "(null)" string

From: Andrà Goddard Rosa
Date: Sun Nov 01 2009 - 09:15:59 EST


Change "<NULL>" to "(null)" and make it a static const char[] hoping that
the compiler will make null_str a label to a read-only area containing it.

See:
http://people.redhat.com/drepper/dsohowto.pdf part 2.4.2
http://udrepper.livejournal.com/13851.html
http://udrepper.livejournal.com/15119.html

Signed-off-by: André Goddard Rosa <andre.goddard@xxxxxxxxx>
---
lib/vsprintf.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 33bed5e..002f462 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -34,6 +34,8 @@
/* Works only for digits and letters, but small and fast */
#define TOLOWER(x) ((x) | 0x20)

+static const char null_str[] = "(null)";
+
static unsigned int simple_guess_base(const char *cp)
{
if (cp[0] == '0') {
@@ -546,12 +548,12 @@ static char *number(char *buf, char *end,
unsigned long long num,
return buf;
}

-static char *string(char *buf, char *end, char *s, struct printf_spec spec)
+static char *string(char *buf, char *end, const char *s, struct
printf_spec spec)
{
int len, i;

if ((unsigned long)s < PAGE_SIZE)
- s = "<NULL>";
+ s = null_str;

len = strnlen(s, spec.precision);

@@ -822,7 +824,7 @@ static char *pointer(const char *fmt, char *buf,
char *end, void *ptr,
struct printf_spec spec)
{
if (!ptr)
- return string(buf, end, "(null)", spec);
+ return string(buf, end, null_str, spec);

switch (*fmt) {
case 'F':
@@ -1445,7 +1447,7 @@ do { \
size_t len;
if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
|| (unsigned long)save_str < PAGE_SIZE)
- save_str = "<NULL>";
+ save_str = null_str;
len = strlen(save_str);
if (str + len + 1 < end)
memcpy(str, save_str, len + 1);
--
1.6.5.2.140.g5f809
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/