faster strlen?

后端 未结 8 2328
小鲜肉
小鲜肉 2021-02-20 15:49

Typical strlen() traverse from first character till it finds \\0. This requires you to traverse each and every character. In algorithm sense, its O(N).

8条回答
  •  伪装坚强ぢ
    2021-02-20 16:22

    Actually, glibc's implementation of strlen is an interesting example of the vectorization approach. It is peculiar in that it doesn't use vector instructions, but finds a way to use only ordinary instructions on 32 or 64 bits words from the buffer.

提交回复
热议问题