@@ -26,16 +26,13 @@ using namespace llvm;
26
26
// / string pairs that is not shared across the whole set of strings. All
27
27
// / strings are assumed to have the same length.
28
28
static unsigned
29
- FindFirstNonCommonLetter (const std::vector<const
30
- StringMatcher::StringPair*> &Matches) {
29
+ FindFirstNonCommonLetter (ArrayRef<const StringMatcher::StringPair *> Matches) {
31
30
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.
36
33
for (const StringMatcher::StringPair *Match : Matches)
37
- if (Match->first [i ] != Letter)
38
- return i ;
34
+ if (Match->first [Idx ] != Letter)
35
+ return Idx ;
39
36
}
40
37
41
38
return Matches[0 ]->first .size ();
@@ -47,8 +44,8 @@ FindFirstNonCommonLetter(const std::vector<const
47
44
// /
48
45
// / \return - True if control can leave the emitted code fragment.
49
46
bool 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 {
52
49
assert (!Matches.empty () && " Must have at least one string to match!" );
53
50
std::string Indent (IndentCount * 2 + 4 , ' ' );
54
51
@@ -110,14 +107,14 @@ bool StringMatcher::EmitStringMatcherForChar(
110
107
OS << Indent << " switch (" << StrVariableName << " [" << CharNo << " ]) {\n " ;
111
108
OS << Indent << " default: break;\n " ;
112
109
113
- for (const auto &LI : MatchesByLetter) {
110
+ for (const auto &[Letter, Matches] : MatchesByLetter) {
114
111
// 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 ()
116
113
<< " string" ;
117
- if (LI. second .size () != 1 )
114
+ if (Matches .size () != 1 )
118
115
OS << ' s' ;
119
116
OS << " to match.\n " ;
120
- if (EmitStringMatcherForChar (LI. second , CharNo + 1 , IndentCount + 1 ,
117
+ if (EmitStringMatcherForChar (Matches , CharNo + 1 , IndentCount + 1 ,
121
118
IgnoreDuplicates))
122
119
OS << Indent << " break;\n " ;
123
120
}
@@ -143,11 +140,11 @@ void StringMatcher::Emit(unsigned Indent, bool IgnoreDuplicates) const {
143
140
OS.indent (Indent*2 +2 ) << " switch (" << StrVariableName << " .size()) {\n " ;
144
141
OS.indent (Indent*2 +2 ) << " default: break;\n " ;
145
142
146
- for (const auto &LI : MatchesByLength) {
143
+ for (const auto &[Length, Matches] : MatchesByLength) {
147
144
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))
151
148
OS.indent (Indent*2 +4 ) << " break;\n " ;
152
149
}
153
150
0 commit comments