faster strlen?

后端 未结 8 2381
小鲜肉
小鲜肉 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:19

    You can try to use vectorization. Not sure if compiler will be able perform it, but I did it manually (using intrinsics). But it could help you only for long strings.

    Use stl strings, it's more safe and std::string class contains its length.

提交回复
热议问题