@@ -26,16 +26,13 @@ using namespace llvm;
2626// / string pairs that is not shared across the whole set of strings. All
2727// / strings are assumed to have the same length.
2828static unsigned
29- FindFirstNonCommonLetter (const std::vector<const
30- StringMatcher::StringPair*> &Matches) {
29+ FindFirstNonCommonLetter (ArrayRef<const StringMatcher::StringPair *> Matches) {
3130 assert (!Matches.empty ());
32- for (unsigned i = 0 , e = Matches[0 ]->first .size (); i != e; ++i) {
33- // Check to see if letter i is the same across the set.
34- char Letter = Matches[0 ]->first [i];
35-
31+ for (auto [Idx, Letter] : enumerate(Matches[0 ]->first )) {
32+ // Check to see if `Letter` is the same across the set.
3633 for (const StringMatcher::StringPair *Match : Matches)
37- if (Match->first [i ] != Letter)
38- return i ;
34+ if (Match->first [Idx ] != Letter)
35+ return Idx ;
3936 }
4037
4138 return Matches[0 ]->first .size ();
@@ -47,8 +44,8 @@ FindFirstNonCommonLetter(const std::vector<const
4744// /
4845// / \return - True if control can leave the emitted code fragment.
4946bool StringMatcher::EmitStringMatcherForChar (
50- const std::vector <const StringPair *> & Matches, unsigned CharNo,
51- unsigned IndentCount, bool IgnoreDuplicates) const {
47+ ArrayRef <const StringPair *> Matches, unsigned CharNo, unsigned IndentCount ,
48+ bool IgnoreDuplicates) const {
5249 assert (!Matches.empty () && " Must have at least one string to match!" );
5350 std::string Indent (IndentCount * 2 + 4 , ' ' );
5451
@@ -110,14 +107,14 @@ bool StringMatcher::EmitStringMatcherForChar(
110107 OS << Indent << " switch (" << StrVariableName << " [" << CharNo << " ]) {\n " ;
111108 OS << Indent << " default: break;\n " ;
112109
113- for (const auto &LI : MatchesByLetter) {
110+ for (const auto &[Letter, Matches] : MatchesByLetter) {
114111 // TODO: escape hard stuff (like \n) if we ever care about it.
115- OS << Indent << " case '" << LI. first << " ':\t // " << LI. second .size ()
112+ OS << Indent << " case '" << Letter << " ':\t // " << Matches .size ()
116113 << " string" ;
117- if (LI. second .size () != 1 )
114+ if (Matches .size () != 1 )
118115 OS << ' s' ;
119116 OS << " to match.\n " ;
120- if (EmitStringMatcherForChar (LI. second , CharNo + 1 , IndentCount + 1 ,
117+ if (EmitStringMatcherForChar (Matches , CharNo + 1 , IndentCount + 1 ,
121118 IgnoreDuplicates))
122119 OS << Indent << " break;\n " ;
123120 }
@@ -143,11 +140,11 @@ void StringMatcher::Emit(unsigned Indent, bool IgnoreDuplicates) const {
143140 OS.indent (Indent*2 +2 ) << " switch (" << StrVariableName << " .size()) {\n " ;
144141 OS.indent (Indent*2 +2 ) << " default: break;\n " ;
145142
146- for (const auto &LI : MatchesByLength) {
143+ for (const auto &[Length, Matches] : MatchesByLength) {
147144 OS.indent (Indent * 2 + 2 )
148- << " case " << LI. first << " :\t // " << LI. second .size () << " string"
149- << (LI. second .size () == 1 ? " " : " s" ) << " to match.\n " ;
150- if (EmitStringMatcherForChar (LI. second , 0 , Indent, IgnoreDuplicates))
145+ << " case " << Length << " :\t // " << Matches .size () << " string"
146+ << (Matches .size () == 1 ? " " : " s" ) << " to match.\n " ;
147+ if (EmitStringMatcherForChar (Matches , 0 , Indent, IgnoreDuplicates))
151148 OS.indent (Indent*2 +4 ) << " break;\n " ;
152149 }
153150
0 commit comments