Optimized version of strstr (search has constant length)

后端 未结 5 1064
孤城傲影
孤城傲影 2020-12-31 08:42

My C program had a lot of strstr function calls. The standard library strstr is already fast but in my case the search string has always length of 5 characters. I replaced i

5条回答
  •  我在风中等你
    2020-12-31 09:08

    Your code may access cs beyond the bounds of its allocation if cs is shorter than 4 characters.

    A common optimisation for string search is to use the Boyer-Moore algorithm where you start looking in cs from the end of what would be ct. See the linked page for a full description of the algorithm.

提交回复
热议问题