This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch dev-1-2-7
in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git

commit 4b4910c463edf29d1b03a3600036b0468a46ae17
Author: Alan M. Carroll <[email protected]>
AuthorDate: Tue Jun 23 06:54:57 2020 -0500

    IPSpace: add check to lower_bound to check if target is past the end and 
immediately return.
---
 code/include/swoc/DiscreteRange.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/code/include/swoc/DiscreteRange.h 
b/code/include/swoc/DiscreteRange.h
index 280e836..eba8bed 100644
--- a/code/include/swoc/DiscreteRange.h
+++ b/code/include/swoc/DiscreteRange.h
@@ -912,6 +912,12 @@ template<typename METRIC, typename PAYLOAD>
 auto DiscreteSpace<METRIC, PAYLOAD>::lower_bound(METRIC const& target) -> Node 
* {
   Node *n = _root;   // current node to test.
   Node *zret = nullptr; // best node so far.
+
+  // Fast check for sequential insertion
+  if (auto ln = _list.tail() ; ln != nullptr && ln->max() < target) {
+    return ln;
+  }
+
   while (n) {
     if (target < n->min()) {
       n = left(n);

Reply via email to