[all-commits] [llvm/llvm-project] 67696a: [ADT] Reduce copies and recursion in StringSwitch ...

Jakub Kuderski via All-commits all-commits at lists.llvm.org
Mon Feb 3 09:09:55 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 67696a1adcd538050674420cab4385730e002524
      https://github.com/llvm/llvm-project/commit/67696a1adcd538050674420cab4385730e002524
  Author: Jakub Kuderski <jakub at nod-labs.com>
  Date:   2025-02-03 (Mon, 03 Feb 2025)

  Changed paths:
    M llvm/include/llvm/ADT/StringSwitch.h
    M llvm/unittests/ADT/StringSwitchTest.cpp

  Log Message:
  -----------
  [ADT] Reduce copies and recursion in StringSwitch (#125362)

Optimize the `.Cases` and `.CasesLower` functions to avoid needlessly
recursing on each case and copying the associated values. We can instead
take `Value` by reference and short-circuit by using the `||` operator.

Note that while the implementation uses variadic templates, we cannot
simplify the public functions in the same way. This is because the
current API forces the arguments to be converted to `StringLiterals` and
places the `Value` parameter at the very end. Even if we did some tricks
like split the parameter pack to separate out the `Value`, I do not see
how we could force conversion to `StringLiteral`.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list