[Bf-blender-cvs] [fa9a630b295] newboolean: Use std::lower_bound instead of custom binary search.

Howard Trickey noreply at git.blender.org
Wed Aug 19 23:48:54 CEST 2020


Commit: fa9a630b29539a9f388bfda7ee3433e2bb37625d
Author: Howard Trickey
Date:   Wed Aug 19 17:48:28 2020 -0400
Branches: newboolean
https://developer.blender.org/rBfa9a630b29539a9f388bfda7ee3433e2bb37625d

Use std::lower_bound instead of custom binary search.

===================================================================

M	source/blender/blenlib/intern/mesh_intersect.cc

===================================================================

diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc
index 98eedbd7edb..d0def5c06a2 100644
--- a/source/blender/blenlib/intern/mesh_intersect.cc
+++ b/source/blender/blenlib/intern/mesh_intersect.cc
@@ -17,6 +17,7 @@
 /* The blender::meshintersect API needs GMP. */
 #ifdef WITH_GMP
 
+#  include <algorithm>
 #  include <fstream>
 #  include <iostream>
 
@@ -2673,19 +2674,13 @@ static int find_first_overlap_index(const TriOverlaps &ov, int t)
   if (span.size() == 0) {
     return -1;
   }
-  int min = 0;
-  int max = static_cast<int>(span.size()) - 1;
-  while (min < max) {
-    int mid = (min + max) / 2;
-    if (t <= span[mid].indexA) {
-      max = mid;
-    }
-    else {
-      min = mid + 1;
-    }
-  }
-  if (span[min].indexA == t) {
-    return min;
+  BVHTreeOverlap bo{t, -1};
+  const BVHTreeOverlap *p = std::lower_bound(
+      span.begin(), span.end(), bo, [](const BVHTreeOverlap &o1, const BVHTreeOverlap &o2) {
+        return o1.indexA < o2.indexA;
+      });
+  if (p != span.end()) {
+    return p - span.begin();
   }
   return -1;
 }



More information about the Bf-blender-cvs mailing list