1 /* Optimized string comparison.
2 Copyright (C) 2001-2002, 2007 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 /* Written by Bruno Haible <bruno@clisp.org>. */
23 /* STREQ allows to optimize string comparison with a small literal string.
24 STREQ (s, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0)
25 is semantically equivalent to
26 strcmp (s, "EUC-KR") == 0
29 /* Help GCC to generate good code for string comparisons with
31 #if defined (__GNUC__) && defined (__OPTIMIZE__)
34 streq9 (const char *s1, const char *s2)
36 return strcmp (s1 + 9, s2 + 9) == 0;
40 streq8 (const char *s1, const char *s2, char s28)
47 return streq9 (s1, s2);
54 streq7 (const char *s1, const char *s2, char s27, char s28)
61 return streq8 (s1, s2, s28);
68 streq6 (const char *s1, const char *s2, char s26, char s27, char s28)
75 return streq7 (s1, s2, s27, s28);
82 streq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28)
89 return streq6 (s1, s2, s26, s27, s28);
96 streq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27, char s28)
103 return streq5 (s1, s2, s25, s26, s27, s28);
110 streq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26, char s27, char s28)
117 return streq4 (s1, s2, s24, s25, s26, s27, s28);
124 streq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
131 return streq3 (s1, s2, s23, s24, s25, s26, s27, s28);
138 streq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
145 return streq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28);
152 streq0 (const char *s1, const char *s2, char s20, char s21, char s22, char s23, char s24, char s25, char s26, char s27, char s28)
159 return streq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28);
165 #define STREQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
166 streq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28)
170 #define STREQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \
171 (strcmp (s1, s2) == 0)