4 ms·
Optimization hacks aside, I swoon at the simple (and verified) seL4 implementation (note strNlen): word_t strnlen(const char *s, word_t maxlen) { wor
by m463 7y ago
Optimization hacks aside, I swoon at the simple (and verified) seL4 implementation (note strNlen):
word_t strnlen(const char *s, word_t maxlen)
{
word_t len;
for (len = 0; len < maxlen && s[len]; len++);
return len;
}
http://sel4.systems/ http://sel4.systems/
https://github.com/seL4/seL4 https://github.com/seL4/seL4 (from file src/string.c)
- ridiculous_fish 7y agoThe trailing semicolon on that for loop is quite load-bearing. I would have some code review feedback.
- goalieca 7y agoLooks very simple to me. I love it.
- anticensor 7y agoIt can be replaced by continue; in this specific case.
- rurban 7y agoNope, for sure not. A good implementation would stick to the standard (size_t nor word_t), and would inc the pointer, not the counter. Formatting would be better (the final ; ouch). This is junior stuff.
- m463 7y agoMaybe verification tools choke on pointer incrementing? Having worked on a variety of code bases and coding styles, I think if there are coding rules and they are consistent across all the source files, it becomes easy to read even with wierdnesses. I hated perl with @_ and $_, but after working with it enough they became known quantities. And you can probably read all the lines of code in your lifetime, since the whole microkernel is ~30k lines of code.