memchr

共1篇文章。

memchr(3) rewrite

• Development

I have taken some time to rewrite memchr(3) to utilize a similar algorithm to my strlen(3). Two different formulas, however, would have roughly a 1/3 difference.

Currently I have taken an approach where, when memchr(3) tries to match an 8-bit pattern, it treats the string as 8-bit using the first formula, which is expected to have uniform O(n)O(n) time complexity by reducing unnecessary branches.

This approach, however, might be bogus: if you look for a 7-bit character within an 8-bit string, memchr(3) will perform poorly when there are many characters with their MSB set to 1.

阅读全文…(本文约109字,阅读大致需要1分钟)