shorten strchr and runestrchr

This commit is contained in:
Amavect 2022-05-22 22:38:11 +00:00 committed by Ori Bernstein
parent 47cff2e833
commit 761bf6c347
2 changed files with 14 additions and 20 deletions

View file

@ -4,17 +4,14 @@
Rune* Rune*
runestrchr(Rune *s, Rune c) runestrchr(Rune *s, Rune c)
{ {
Rune c0 = c; Rune r;
Rune c1;
if(c == 0) { if(c == 0)
while(*s++) while(*s++)
; ;
return s-1; else
} while((r = *s++) != c)
if(r == 0)
while(c1 = *s++)
if(c1 == c0)
return s-1;
return 0; return 0;
return s-1;
} }

View file

@ -4,17 +4,14 @@
char* char*
strchr(char *s, int c) strchr(char *s, int c)
{ {
char c0 = c; char r;
char c1;
if(c == 0) { if(c == 0)
while(*s++) while(*s++)
; ;
return s-1; else
} while((r = *s++) != c)
if(r == 0)
while(c1 = *s++)
if(c1 == c0)
return s-1;
return 0; return 0;
return s-1;
} }