@@ -74,18 +74,14 @@ SourceComparator::buildEquivalenceClasses() {
74
74
return rhsMap;
75
75
}
76
76
77
- std::unique_ptr<SourceComparator::PRLink>
78
- SourceComparator::newPRLink (LineIndices lines, PRLink *next) {
79
- return llvm::make_unique<PRLink>(lines, next);
80
- }
81
77
82
- std::pair<std::vector<std::unique_ptr< SourceComparator::PRLink> >,
78
+ std::pair<std::vector<SourceComparator::PRLink>,
83
79
SourceComparator::SortedSequence>
84
80
SourceComparator::buildDAGOfSubsequences (
85
81
std::unordered_map<std::string, std::vector<size_t >> rhsMap) {
86
82
SortedSequence thresh;
87
83
const size_t linksSize = regionsToCompare.size ().min ();
88
- std::vector<std::unique_ptr< PRLink> > links;
84
+ std::vector<PRLink> links;
89
85
links.resize (linksSize);
90
86
91
87
for (auto i = regionsToCompare.start .lhs (); i < regionsToCompare.end .lhs ();
@@ -108,25 +104,27 @@ SourceComparator::buildDAGOfSubsequences(
108
104
auto k = optK.getValue ();
109
105
// prev match (of what?) was at links[k-1]?
110
106
// chain to that match
111
- PRLink * newNext = k == 0 ? nullptr : links[ k - 1 ]. get ( );
112
- links[k] = newPRLink ( LineIndices (i, j), newNext);
107
+ Optional< size_t > newNext = k == 0 ? None : Optional< size_t >( k - 1 );
108
+ links. emplace (links. begin () + k, LineIndices (i, j), newNext);
113
109
}
114
110
}
115
111
}
116
112
return {std::move (links), thresh};
117
113
}
118
114
119
115
void SourceComparator::scanMatchedLines (
120
- std::pair<std::vector<std::unique_ptr< PRLink> >, SortedSequence>
116
+ std::pair<std::vector<PRLink>, SortedSequence>
121
117
&&linksAndThres) {
122
118
const auto &links = linksAndThres.first ;
123
119
const auto &thresh = linksAndThres.second ;
124
120
121
+ if (thresh.empty ())
122
+ return ;
125
123
// For every match put rhs index in matches[col2 index]
126
- for (const PRLink *lnk = thresh.empty () ? nullptr
127
- : links[thresh. size () - 1 ]. get () ;
128
- lnk; lnk = lnk ->next )
129
- matches[lnk ->lines .lhs ()] = lnk ->lines .rhs ();
124
+ for (const auto *p = &links[ thresh.size () - 1 ];
125
+ p ;
126
+ p = p ->next ? &links[p-> next . getValue ()] : nullptr )
127
+ matches[p ->lines .lhs ()] = p ->lines .rhs ();
130
128
}
131
129
132
130
// ==============================================================================
0 commit comments