Index: include/llvm/ADT/StringSwitch.h =================================================================== --- include/llvm/ADT/StringSwitch.h +++ include/llvm/ADT/StringSwitch.h @@ -75,7 +75,6 @@ (std::memcmp(S, Str.data(), N-1) == 0)) { Result = &Value; } - return *this; } @@ -86,7 +85,6 @@ std::memcmp(S, Str.data() + Str.size() + 1 - N, N-1) == 0) { Result = &Value; } - return *this; } @@ -97,7 +95,6 @@ std::memcmp(S, Str.data(), N-1) == 0) { Result = &Value; } - return *this; } @@ -110,7 +107,6 @@ (N1-1 == Str.size() && std::memcmp(S1, Str.data(), N1-1) == 0))) { Result = &Value; } - return *this; } @@ -124,7 +120,6 @@ (N2-1 == Str.size() && std::memcmp(S2, Str.data(), N2-1) == 0))) { Result = &Value; } - return *this; } @@ -140,7 +135,6 @@ (N3-1 == Str.size() && std::memcmp(S3, Str.data(), N3-1) == 0))) { Result = &Value; } - return *this; } @@ -157,7 +151,67 @@ (N4-1 == Str.size() && std::memcmp(S4, Str.data(), N4-1) == 0))) { Result = &Value; } + return *this; + } + template + LLVM_ATTRIBUTE_ALWAYS_INLINE + StringSwitch& Cases(const char (&S0)[N0], const char (&S1)[N1], + const char (&S2)[N2], const char (&S3)[N3], + const char (&S4)[N4], const char (&S5)[N5], + const T& Value) { + if (!Result && ( + (N0-1 == Str.size() && std::memcmp(S0, Str.data(), N0-1) == 0) || + (N1-1 == Str.size() && std::memcmp(S1, Str.data(), N1-1) == 0) || + (N2-1 == Str.size() && std::memcmp(S2, Str.data(), N2-1) == 0) || + (N3-1 == Str.size() && std::memcmp(S3, Str.data(), N3-1) == 0) || + (N4-1 == Str.size() && std::memcmp(S4, Str.data(), N4-1) == 0) || + (N5-1 == Str.size() && std::memcmp(S5, Str.data(), N5-1) == 0))) { + Result = &Value; + } + return *this; + } + + template + LLVM_ATTRIBUTE_ALWAYS_INLINE + StringSwitch& Cases(const char (&S0)[N0], const char (&S1)[N1], + const char (&S2)[N2], const char (&S3)[N3], + const char (&S4)[N4], const char (&S5)[N5], + const char (&S6)[N6], const T& Value) { + if (!Result && ( + (N0-1 == Str.size() && std::memcmp(S0, Str.data(), N0-1) == 0) || + (N1-1 == Str.size() && std::memcmp(S1, Str.data(), N1-1) == 0) || + (N2-1 == Str.size() && std::memcmp(S2, Str.data(), N2-1) == 0) || + (N3-1 == Str.size() && std::memcmp(S3, Str.data(), N3-1) == 0) || + (N4-1 == Str.size() && std::memcmp(S4, Str.data(), N4-1) == 0) || + (N5-1 == Str.size() && std::memcmp(S5, Str.data(), N5-1) == 0) || + (N6-1 == Str.size() && std::memcmp(S6, Str.data(), N6-1) == 0))) { + Result = &Value; + } + return *this; + } + + template + LLVM_ATTRIBUTE_ALWAYS_INLINE + StringSwitch& Cases(const char (&S0)[N0], const char (&S1)[N1], + const char (&S2)[N2], const char (&S3)[N3], + const char (&S4)[N4], const char (&S5)[N5], + const char (&S6)[N6], const char (&S7)[N7], + const T& Value) { + if (!Result && ( + (N0-1 == Str.size() && std::memcmp(S0, Str.data(), N0-1) == 0) || + (N1-1 == Str.size() && std::memcmp(S1, Str.data(), N1-1) == 0) || + (N2-1 == Str.size() && std::memcmp(S2, Str.data(), N2-1) == 0) || + (N3-1 == Str.size() && std::memcmp(S3, Str.data(), N3-1) == 0) || + (N4-1 == Str.size() && std::memcmp(S4, Str.data(), N4-1) == 0) || + (N5-1 == Str.size() && std::memcmp(S5, Str.data(), N5-1) == 0) || + (N6-1 == Str.size() && std::memcmp(S6, Str.data(), N6-1) == 0) || + (N7-1 == Str.size() && std::memcmp(S7, Str.data(), N7-1) == 0))) { + Result = &Value; + } return *this; } @@ -165,7 +219,6 @@ R Default(const T& Value) const { if (Result) return *Result; - return Value; }