Optimize match to one loop
This commit is contained in:
parent
652e40da30
commit
a4f28850de
10
c/cosmic.c
10
c/cosmic.c
|
@ -1,5 +1,5 @@
|
|||
int match(const char *needle, const char *haystack) {
|
||||
while(*haystack) {
|
||||
while(*haystack || *needle) {
|
||||
if(*needle == '*' && *(needle + 1) == '*') {
|
||||
needle += 1;
|
||||
} else if(*needle == '*') {
|
||||
|
@ -7,6 +7,8 @@ int match(const char *needle, const char *haystack) {
|
|||
return 1;
|
||||
} else if(*(needle + 1) == *haystack) {
|
||||
needle += 1;
|
||||
} else if(*haystack == '\0') {
|
||||
needle += 1;
|
||||
} else {
|
||||
haystack += 1;
|
||||
}
|
||||
|
@ -18,11 +20,7 @@ int match(const char *needle, const char *haystack) {
|
|||
}
|
||||
}
|
||||
|
||||
while(*needle == '*') {
|
||||
needle += 1;
|
||||
}
|
||||
|
||||
return *needle == '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
|
Loading…
Reference in New Issue