@@ -29,8 +29,7 @@ using namespace incremental_ranges;
29
29
SourceComparator::SourceComparator (StringRef s1, StringRef s2)
30
30
: linesToCompare(splitIntoLines(s1), splitIntoLines(s2)),
31
31
regionsToCompare(LineSpan({0 , 0 }, linesToCompare.size())),
32
- matches(linesToCompare.lhs().size(), None),
33
- linkVec(regionsToCompare.end.min(), PRLink()) {}
32
+ matches(linesToCompare.lhs().size(), None) {}
34
33
35
34
std::vector<StringRef> SourceComparator::splitIntoLines (const StringRef s) {
36
35
std::vector<StringRef> result;
@@ -75,24 +74,19 @@ SourceComparator::buildEquivalenceClasses() {
75
74
return rhsMap;
76
75
}
77
76
78
- SourceComparator::PRLink *SourceComparator::newPRLink (LineIndices lines,
79
- PRLink *next) {
80
- if (nextLink >= linkVec.size ())
81
- linkVec.emplace_back ();
82
- assert (nextLink < linkVec.size ());
83
- PRLink &link = linkVec[nextLink++];
84
- link.lines = lines;
85
- link.next = next;
86
- return &link;
77
+ std::unique_ptr<SourceComparator::PRLink>
78
+ SourceComparator::newPRLink (LineIndices lines, PRLink *next) {
79
+ return llvm::make_unique<PRLink>(lines, next);
87
80
}
88
81
89
- std::pair<std::vector<SourceComparator::PRLink * >,
82
+ std::pair<std::vector<std::unique_ptr< SourceComparator::PRLink> >,
90
83
SourceComparator::SortedSequence>
91
84
SourceComparator::buildDAGOfSubsequences (
92
85
std::unordered_map<std::string, std::vector<size_t >> rhsMap) {
93
86
SortedSequence thresh;
94
87
const size_t linksSize = regionsToCompare.size ().min ();
95
- std::vector<PRLink *> links (linksSize, nullptr );
88
+ std::vector<std::unique_ptr<PRLink>> links;
89
+ links.resize (linksSize);
96
90
97
91
for (auto i = regionsToCompare.start .lhs (); i < regionsToCompare.end .lhs ();
98
92
++i) {
@@ -114,23 +108,24 @@ SourceComparator::buildDAGOfSubsequences(
114
108
auto k = optK.getValue ();
115
109
// prev match (of what?) was at links[k-1]?
116
110
// chain to that match
117
- PRLink *newNext = k == 0 ? nullptr : links[k - 1 ];
111
+ PRLink *newNext = k == 0 ? nullptr : links[k - 1 ]. get () ;
118
112
links[k] = newPRLink (LineIndices (i, j), newNext);
119
113
}
120
114
}
121
115
}
122
- return {links, thresh};
116
+ return {std::move ( links) , thresh};
123
117
}
124
118
125
119
void SourceComparator::scanMatchedLines (
126
- std::pair<std::vector<PRLink *>, SortedSequence> linksAndThres) {
127
- auto links = linksAndThres.first ;
128
- auto thresh = linksAndThres.second ;
120
+ std::pair<std::vector<std::unique_ptr<PRLink>>, SortedSequence>
121
+ &&linksAndThres) {
122
+ const auto &links = linksAndThres.first ;
123
+ const auto &thresh = linksAndThres.second ;
129
124
130
125
// For every match put rhs index in matches[col2 index]
131
- for (auto lnk = thresh.empty () ? nullptr : links[thresh. size () - 1 ];
132
- lnk ;
133
- lnk = lnk->next )
126
+ for (const PRLink * lnk = thresh.empty () ? nullptr
127
+ : links[thresh. size () - 1 ]. get () ;
128
+ lnk; lnk = lnk->next )
134
129
matches[lnk->lines .lhs ()] = lnk->lines .rhs ();
135
130
}
136
131
0 commit comments