[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
A simple optimization for strcmp()
From: |
Soeren Sandmann |
Subject: |
A simple optimization for strcmp() |
Date: |
02 May 2003 15:21:11 +0200 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
I'm not sure I'm sending this to the right address. If not, please
tell where I should send it.
The patch below has a simple optimization for strcmp() for the case
where the two passed pointers are identical. By returning immediately
in that case, you avoid reading both strings in from memory.
I think this is a fairly common case, because constant strings are
often used as identifiers.
Sorry, I haven't benchmarked it.
Søren
--- strcmp.c.orig Fri May 2 15:07:44 2003
+++ strcmp.c Fri May 2 15:08:12 2003
@@ -33,6 +33,9 @@
register const unsigned char *s2 = (const unsigned char *) p2;
unsigned reg_char c1, c2;
+ if (p1 == p2)
+ return 0;
+
do
{
c1 = (unsigned char) *s1++;
- A simple optimization for strcmp(),
Soeren Sandmann <=