Hi Alex, > This code seems overly complex to me. A do-while seems unintuitive when > you're not performing at least 1 iteration, and having an if that is > basically the same operation as the while condition seems weird. Maybe > I'm missing something, but it looks like it can be written more readable as:
I have no objections to changing the code. For my initial submission, I figured I'd use an implementation that comes directly from Apple's own open source server. But if the consensus is to tweak the code to make it smaller / faster / more readable, that's alright by me. I only want CGIT to build on macOS. :-) > void * > memrchr(const void *s, int c, size_t n) > { > unsigned char ch; > const unsigned char *cp; > > ch = c; > > cp = s; > for (cp += n; n != 0; n--) { > cp--; > if (*cp == ch) > return (void *) cp; > } > > return NULL; > } Let me play around with this. > Clang produces similar assembly code for both. GCC however produces > smaller code for the for loop. Thanks for the feedback. Regards, -Markus