OLD | NEW |
(Empty) | |
| 1 /* -*- buffer-read-only: t -*- vi: set ro: */ |
| 2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */ |
| 3 /* Optimized string comparison. |
| 4 Copyright (C) 2001-2002, 2007 Free Software Foundation, Inc. |
| 5 |
| 6 This program is free software: you can redistribute it and/or modify it |
| 7 under the terms of the GNU General Public License as published |
| 8 by the Free Software Foundation; either version 3 of the License, or |
| 9 (at your option) any later version. |
| 10 |
| 11 This program is distributed in the hope that it will be useful, |
| 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 Lesser General Public License for more details. |
| 15 |
| 16 You should have received a copy of the GNU General Public License |
| 17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 18 |
| 19 /* Written by Bruno Haible <bruno@clisp.org>. */ |
| 20 |
| 21 #ifndef _GL_STREQ_H |
| 22 #define _GL_STREQ_H |
| 23 |
| 24 #include <string.h> |
| 25 |
| 26 /* STREQ allows to optimize string comparison with a small literal string. |
| 27 STREQ (s, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) |
| 28 is semantically equivalent to |
| 29 strcmp (s, "EUC-KR") == 0 |
| 30 just faster. */ |
| 31 |
| 32 /* Help GCC to generate good code for string comparisons with |
| 33 immediate strings. */ |
| 34 #if defined (__GNUC__) && defined (__OPTIMIZE__) |
| 35 |
| 36 static inline int |
| 37 streq9 (const char *s1, const char *s2) |
| 38 { |
| 39 return strcmp (s1 + 9, s2 + 9) == 0; |
| 40 } |
| 41 |
| 42 static inline int |
| 43 streq8 (const char *s1, const char *s2, char s28) |
| 44 { |
| 45 if (s1[8] == s28) |
| 46 { |
| 47 if (s28 == 0) |
| 48 return 1; |
| 49 else |
| 50 return streq9 (s1, s2); |
| 51 } |
| 52 else |
| 53 return 0; |
| 54 } |
| 55 |
| 56 static inline int |
| 57 streq7 (const char *s1, const char *s2, char s27, char s28) |
| 58 { |
| 59 if (s1[7] == s27) |
| 60 { |
| 61 if (s27 == 0) |
| 62 return 1; |
| 63 else |
| 64 return streq8 (s1, s2, s28); |
| 65 } |
| 66 else |
| 67 return 0; |
| 68 } |
| 69 |
| 70 static inline int |
| 71 streq6 (const char *s1, const char *s2, char s26, char s27, char s28) |
| 72 { |
| 73 if (s1[6] == s26) |
| 74 { |
| 75 if (s26 == 0) |
| 76 return 1; |
| 77 else |
| 78 return streq7 (s1, s2, s27, s28); |
| 79 } |
| 80 else |
| 81 return 0; |
| 82 } |
| 83 |
| 84 static inline int |
| 85 streq5 (const char *s1, const char *s2, char s25, char s26, char s27, char s28) |
| 86 { |
| 87 if (s1[5] == s25) |
| 88 { |
| 89 if (s25 == 0) |
| 90 return 1; |
| 91 else |
| 92 return streq6 (s1, s2, s26, s27, s28); |
| 93 } |
| 94 else |
| 95 return 0; |
| 96 } |
| 97 |
| 98 static inline int |
| 99 streq4 (const char *s1, const char *s2, char s24, char s25, char s26, char s27,
char s28) |
| 100 { |
| 101 if (s1[4] == s24) |
| 102 { |
| 103 if (s24 == 0) |
| 104 return 1; |
| 105 else |
| 106 return streq5 (s1, s2, s25, s26, s27, s28); |
| 107 } |
| 108 else |
| 109 return 0; |
| 110 } |
| 111 |
| 112 static inline int |
| 113 streq3 (const char *s1, const char *s2, char s23, char s24, char s25, char s26,
char s27, char s28) |
| 114 { |
| 115 if (s1[3] == s23) |
| 116 { |
| 117 if (s23 == 0) |
| 118 return 1; |
| 119 else |
| 120 return streq4 (s1, s2, s24, s25, s26, s27, s28); |
| 121 } |
| 122 else |
| 123 return 0; |
| 124 } |
| 125 |
| 126 static inline int |
| 127 streq2 (const char *s1, const char *s2, char s22, char s23, char s24, char s25,
char s26, char s27, char s28) |
| 128 { |
| 129 if (s1[2] == s22) |
| 130 { |
| 131 if (s22 == 0) |
| 132 return 1; |
| 133 else |
| 134 return streq3 (s1, s2, s23, s24, s25, s26, s27, s28); |
| 135 } |
| 136 else |
| 137 return 0; |
| 138 } |
| 139 |
| 140 static inline int |
| 141 streq1 (const char *s1, const char *s2, char s21, char s22, char s23, char s24,
char s25, char s26, char s27, char s28) |
| 142 { |
| 143 if (s1[1] == s21) |
| 144 { |
| 145 if (s21 == 0) |
| 146 return 1; |
| 147 else |
| 148 return streq2 (s1, s2, s22, s23, s24, s25, s26, s27, s28); |
| 149 } |
| 150 else |
| 151 return 0; |
| 152 } |
| 153 |
| 154 static inline int |
| 155 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) |
| 156 { |
| 157 if (s1[0] == s20) |
| 158 { |
| 159 if (s20 == 0) |
| 160 return 1; |
| 161 else |
| 162 return streq1 (s1, s2, s21, s22, s23, s24, s25, s26, s27, s28); |
| 163 } |
| 164 else |
| 165 return 0; |
| 166 } |
| 167 |
| 168 #define STREQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \ |
| 169 streq0 (s1, s2, s20, s21, s22, s23, s24, s25, s26, s27, s28) |
| 170 |
| 171 #else |
| 172 |
| 173 #define STREQ(s1,s2,s20,s21,s22,s23,s24,s25,s26,s27,s28) \ |
| 174 (strcmp (s1, s2) == 0) |
| 175 |
| 176 #endif |
| 177 |
| 178 #endif /* _GL_STREQ_H */ |
OLD | NEW |