Mercurial > hg > xemacs-beta
comparison src/strcmp.c @ 442:abe6d1db359e r21-2-36
Import from CVS: tag r21-2-36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:35:02 +0200 |
parents | 3ecd8885ac67 |
children |
comparison
equal
deleted
inserted
replaced
441:72a7cfa4a488 | 442:abe6d1db359e |
---|---|
34 | 34 |
35 #define MAGIC 0x7efefeff | 35 #define MAGIC 0x7efefeff |
36 #define HIGH_BIT_P(c) ((c) & hi_bit) | 36 #define HIGH_BIT_P(c) ((c) & hi_bit) |
37 #define HAS_ZERO(c) (((((c) + magic) ^ (c)) & not_magic) != not_magic) | 37 #define HAS_ZERO(c) (((((c) + magic) ^ (c)) & not_magic) != not_magic) |
38 | 38 |
39 /* CONST IS LOSING, but const is part of the interface of strcmp */ | |
40 int | 39 int |
41 strcmp (const char *x, const char *y) | 40 strcmp (const char *x, const char *y) |
42 { | 41 { |
43 if (x == y) | 42 if (x == y) |
44 return 0; | 43 return 0; |
45 else if (ALIGNED (x) && ALIGNED (y)) | 44 else if (ALIGNED (x) && ALIGNED (y)) |
46 { | 45 { |
47 CONST unsigned long *x1 = (CONST unsigned long *) x; | 46 const unsigned long *x1 = (const unsigned long *) x; |
48 CONST unsigned long *y1 = (CONST unsigned long *) y; | 47 const unsigned long *y1 = (const unsigned long *) y; |
49 unsigned long c; | 48 unsigned long c; |
50 unsigned long magic = MAGIC; | 49 unsigned long magic = MAGIC; |
51 unsigned long not_magic = ~magic; | 50 unsigned long not_magic = ~magic; |
52 unsigned long hi_bit = 0x80000000; | 51 unsigned long hi_bit = 0x80000000; |
53 | 52 |
57 { | 56 { |
58 if (!HIGH_BIT_P (c)) | 57 if (!HIGH_BIT_P (c)) |
59 return 0; | 58 return 0; |
60 else | 59 else |
61 { | 60 { |
62 x = (CONST char *) x1; | 61 x = (const char *) x1; |
63 y = (CONST char *) y1; | 62 y = (const char *) y1; |
64 goto slow_loop; | 63 goto slow_loop; |
65 } | 64 } |
66 } | 65 } |
67 | 66 |
68 x1++; | 67 x1++; |
69 y1++; | 68 y1++; |
70 } | 69 } |
71 | 70 |
72 x = (CONST char *) x1; | 71 x = (const char *) x1; |
73 y = (CONST char *) y1; | 72 y = (const char *) y1; |
74 goto slow_loop; | 73 goto slow_loop; |
75 } | 74 } |
76 else | 75 else |
77 { | 76 { |
78 char c; | 77 char c; |
89 } | 88 } |
90 } | 89 } |
91 | 90 |
92 | 91 |
93 int | 92 int |
94 strncmp (CONST char *x, CONST char *y, size_t n) | 93 strncmp (const char *x, const char *y, size_t n) |
95 { | 94 { |
96 if ((x == y) || (n <= 0)) | 95 if ((x == y) || (n <= 0)) |
97 return 0; | 96 return 0; |
98 else if (ALIGNED (x) && ALIGNED (y)) | 97 else if (ALIGNED (x) && ALIGNED (y)) |
99 { | 98 { |
100 CONST unsigned long *x1 = (CONST unsigned long *) x; | 99 const unsigned long *x1 = (const unsigned long *) x; |
101 CONST unsigned long *y1 = (CONST unsigned long *) y; | 100 const unsigned long *y1 = (const unsigned long *) y; |
102 unsigned long c; | 101 unsigned long c; |
103 unsigned long magic = MAGIC; | 102 unsigned long magic = MAGIC; |
104 unsigned long not_magic = ~magic; | 103 unsigned long not_magic = ~magic; |
105 unsigned long hi_bit = 0x80000000; | 104 unsigned long hi_bit = 0x80000000; |
106 | 105 |
114 { | 113 { |
115 if (!HIGH_BIT_P (c)) | 114 if (!HIGH_BIT_P (c)) |
116 return 0; | 115 return 0; |
117 else | 116 else |
118 { | 117 { |
119 x = (CONST char *) x1; | 118 x = (const char *) x1; |
120 y = (CONST char *) y1; | 119 y = (const char *) y1; |
121 goto slow_loop; | 120 goto slow_loop; |
122 } | 121 } |
123 } | 122 } |
124 | 123 |
125 x1++; | 124 x1++; |
126 y1++; | 125 y1++; |
127 } | 126 } |
128 | 127 |
129 x = (CONST char *) x1; | 128 x = (const char *) x1; |
130 y = (CONST char *) y1; | 129 y = (const char *) y1; |
131 goto slow_loop; | 130 goto slow_loop; |
132 } | 131 } |
133 else | 132 else |
134 { | 133 { |
135 char c; | 134 char c; |