Skip to content

Commit

Permalink
Add comment to sorting function
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardo-elizondo authored and yonghong-song committed Nov 15, 2021
1 parent 8fc16e2 commit ffec628
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cc/usdt/usdt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ void Probe::add_location(uint64_t addr, const std::string &bin_path, const char
}

void Probe::finalize_locations() {
// The following comparator needs to establish a strict weak ordering relation. Such
// that when x < y == true, y < x == false. Otherwise it leads to undefined behavior.
// To guarantee this, it uses std::tie which allows the lambda to have a lexicographical
// comparison and hence, guarantee the strict weak ordering.
std::sort(locations_.begin(), locations_.end(),
[](const Location &a, const Location &b) {
return std::tie(a.bin_path_, a.address_) < std::tie(b.bin_path_, b.address_);
Expand Down

0 comments on commit ffec628

Please sign in to comment.