@@ -36,8 +36,7 @@ int strcmp(const char* s1, const char* s2)
3636 return (* (const unsigned char * )s1 - * (const unsigned char * )(s2 - 1 ));
3737}
3838
39- int stricmp (const char * s1 , const char * s2 )
40- {
39+ int stricmp (const char * s1 , const char * s2 ) {
4140 if (!s1 || !s2 ) {
4241 return (int )s1 - (int )s2 ;
4342 }
@@ -47,8 +46,7 @@ int stricmp(const char* s1, const char* s2)
4746 return (* (const unsigned char * )s1 - * (const unsigned char * )(s2 - 1 ));
4847}
4948
50- char * strchr (const char * s , int c )
51- {
49+ char * strchr (const char * s , int c ) {
5250 if (!s ) {
5351 return NULL ;
5452 }
@@ -88,35 +86,26 @@ int strnicmp(const char* s1, const char* s2, uint32_t n)
8886
8987#include <stdint.h>
9088
91- __attribute__((hot )) int strncmp (const char * s1 , const char * s2 , uint32_t n )
92- {
89+ __attribute__((hot )) int strncmp (const char * s1 , const char * s2 , uint32_t n ) {
9390 if (!s1 || !s2 ) {
94- return (int )s1 - (int )s2 ; /* preserve your NULL behaviour */
91+ return (int )s1 - (int )s2 ;
9592 }
96-
9793 if (s1 == s2 || n == 0 ) {
9894 return 0 ;
9995 }
100-
10196 const unsigned char * p1 = (const unsigned char * )s1 ;
10297 const unsigned char * p2 = (const unsigned char * )s2 ;
103-
10498 while (n -- ) {
10599 unsigned char a = * p1 ++ ;
106100 unsigned char b = * p2 ++ ;
107-
108- /* Common case: bytes equal and not NUL → continue. */
109101 if (__builtin_expect (a == b , 1 )) {
110102 if (__builtin_expect (a != 0u , 1 )) {
111103 continue ;
112104 }
113- return 0 ; /* both NUL at same position */
105+ return 0 ;
114106 }
115-
116- /* First difference decides the result. */
117107 return (int )a - (int )b ;
118108 }
119-
120109 return 0 ;
121110}
122111
0 commit comments