@@ -41,6 +41,8 @@ namespace llvm {
4141// / .Cases({"violet", "purple"}, Violet)
4242// / .Default(UnknownColor);
4343// / \endcode
44+ // /
45+ // / When multiple matches are found, the value of the first match is returned.
4446template <typename T, typename R = T>
4547class StringSwitch {
4648 // / The string we are matching.
@@ -213,23 +215,30 @@ class StringSwitch {
213215 [[nodiscard]] operator R () { return DefaultUnreachable (); }
214216
215217private:
216- // Returns true when `Str` matches the `S` argument, and stores the result.
218+ // Returns true when a match is found. If `Str` matches the `S` argument,
219+ // stores the result.
217220 bool CaseImpl (StringLiteral S, T &Value) {
218- if (!Result && Str == S) {
219- Result = std::move (Value);
221+ if (Result)
220222 return true ;
221- }
222- return false ;
223+
224+ if (Str != S)
225+ return false ;
226+
227+ Result = std::move (Value);
228+ return true ;
223229 }
224230
225- // Returns true when `Str` matches the `S` argument (case-insensitive), and
226- // stores the result.
231+ // Returns true when a match is found. If `Str` matches the `S` argument
232+ // (case-insensitive), stores the result.
227233 bool CaseLowerImpl (StringLiteral S, T &Value) {
228- if (!Result && Str.equals_insensitive (S)) {
229- Result = std::move (Value);
234+ if (Result)
230235 return true ;
231- }
232- return false ;
236+
237+ if (!Str.equals_insensitive (S))
238+ return false ;
239+
240+ Result = std::move (Value);
241+ return true ;
233242 }
234243
235244 StringSwitch &CasesImpl (std::initializer_list<StringLiteral> Cases,
0 commit comments