lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 08 Dec 2006 14:24:45 +0100
From:	"Ulrich Windl" <ulrich.windl@...uni-regensburg.de>
To:	linux-kernel@...r.kernel.org
Subject: 2.6.19: slight performance optimization for lib/string.c's strstrip()

Hi,

my apologies for disobeying all the rules for submitting patches, but I'll suggest 
a performance optimization for strstrip() in lib/string.c:

Original routine:
char *strstrip(char *s)
{
       size_t size;
       char *end;

       size = strlen(s);

       if (!size)
               return s;

       end = s + size - 1;
       while (end >= s && isspace(*end))
               end--;
       *(end + 1) = '\0';

       while (*s && isspace(*s))
               s++;

       return s;
}
EXPORT_SYMBOL(strstrip);


Suggested replacement:

char *strstrip(char *s)
{
       size_t size;
       char *end;

       while (*s && isspace(*s))
               s++;
       if (!*s)
               return s;
       size = strlen(s);

       end = s + size - 1;
       while (end > s && isspace(*end))
               end--;
       *(end + 1) = '\0';

       return s;
}
EXPORT_SYMBOL(strstrip);

Comments: There's no need to scan the initial banks at the start of the string 
twice (using strlen(), and then looking for initial blanks), and we know that the 
first character of the string cannot be a blank when we are removing trailing 
blanks after having removed leading blanks. Also we do not need to call strlen() 
to detect an empty string.

Regards,
Ulrich

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ