Add comment to sorting function
authorEddie Elizondo <eelizondo@fb.com>
Mon, 15 Nov 2021 15:34:43 +0000 (10:34 -0500)
committeryonghong-song <ys114321@gmail.com>
Mon, 15 Nov 2021 17:31:10 +0000 (09:31 -0800)
src/cc/usdt/usdt.cc

index bd3f26517127d056b75898ec150f629b1e05e7f9..e3d0c4417e37c17282c5de1f1a1b8424383e3c27 100644 (file)
@@ -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_);