Skip to content

Commit 36366d2

Browse files
authored
[NFC] Make code less demanding on STL iterators. (#7894)
1 parent 6b5a7d9 commit 36366d2

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

src/passes/Metrics.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,17 @@ struct Metrics
195195
keys.push_back("[total]");
196196
counts["[total]"] = total;
197197
// sort
198-
sort(keys.begin(), keys.end(), [](const char* a, const char* b) -> bool {
199-
// Sort the [..] ones first.
200-
if (a[0] == '[' && b[0] != '[') {
201-
return true;
202-
}
203-
if (a[0] != '[' && b[0] == '[') {
204-
return false;
205-
}
206-
return strcmp(b, a) > 0;
207-
});
198+
std::sort(
199+
keys.begin(), keys.end(), [](const char* a, const char* b) -> bool {
200+
// Sort the [..] ones first.
201+
if (a[0] == '[' && b[0] != '[') {
202+
return true;
203+
}
204+
if (a[0] != '[' && b[0] == '[') {
205+
return false;
206+
}
207+
return strcmp(b, a) > 0;
208+
});
208209
o << title << "\n";
209210
for (auto* key : keys) {
210211
auto value = counts[key];

src/passes/ReorderLocals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct ReorderLocals : public WalkerPass<PostWalker<ReorderLocals>> {
6767
newToOld[i] = i;
6868
}
6969
// sort, keeping params in front (where they will not be moved)
70-
sort(
70+
std::sort(
7171
newToOld.begin(), newToOld.end(), [this, curr](Index a, Index b) -> bool {
7272
if (curr->isParam(a) && !curr->isParam(b)) {
7373
return true;

src/support/strongly_connected_components.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ template<typename It, typename Class> struct SCCs {
3939
SCCs(It inputIt, It inputEnd) : inputIt(inputIt), inputEnd(inputEnd) {}
4040

4141
private:
42-
using T = typename It::value_type;
42+
using T = typename std::iterator_traits<It>::value_type;
4343

4444
// The iterators over the graph we are calculating the SCCs for.
4545
It inputIt;

src/support/topological_sort.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ std::vector<Index> minSort(const Graph& graph, F cmp = std::less<Index>{});
5353
// their children.
5454
template<typename It, typename SortT, SortT Sort, typename... Args>
5555
decltype(auto) sortOfImpl(It begin, It end, Args... args) {
56-
using T = std::remove_cv_t<typename It::value_type::first_type>;
56+
using T =
57+
std::remove_cv_t<typename std::iterator_traits<It>::value_type::first_type>;
5758
std::unordered_map<T, Index> indices;
5859
std::vector<T> elements;
5960
// Assign indices to each element.

0 commit comments

Comments
 (0)