[all-commits] [llvm/llvm-project] 826f38: [Support] Use find() for faster StringRef::count (...

Tatsuyuki Ishi via All-commits all-commits at lists.llvm.org
Thu Oct 27 01:22:41 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 826f38534816ff2890639e3a75d9d7381ffde5ac
      https://github.com/llvm/llvm-project/commit/826f38534816ff2890639e3a75d9d7381ffde5ac
  Author: Tatsuyuki Ishi <ishitatsuyuki at gmail.com>
  Date:   2022-10-27 (Thu, 27 Oct 2022)

  Changed paths:
    M llvm/lib/Support/StringRef.cpp

  Log Message:
  -----------
  [Support] Use find() for faster StringRef::count (NFC)

While profiling InclusionRewriter, it was found that counting lines was
so slow that it took up 20% of the processing time. Surely, calling
memcmp() of size 1 on every substring in the window isn't a good idea.

Use StringRef::find() instead; in the case of N=1 it will forward to
memcmp which is much more optimal. For 2<=N<256 it will run the same
memcmp loop as we have now, which is still suboptimal but at least does
not regress anything.

Differential Revision: https://reviews.llvm.org/D133658




More information about the All-commits mailing list