[PATCH] D52697: Bug 39129: Speeding up partition_point/lower_bound/upper_bound by using unsigned difference_type when possible.
    Denis Yaroshevskiy via Phabricator 
    reviews at reviews.llvm.org
       
    Sat Sep 29 14:46:36 PDT 2018
    
    
  
dyaroshev added a comment.
Unfortunately didn't manage to run a clang-format on my changes - it kept ignoring the library settings - so probably the formatting needs to be reviewed too.
Offtopic: compiling and running benchmarks is non-trivial - I had to lurk through Makefiles to realize how to compile them and then there was a link error with file system stuff. Updating the docs would be great.
================
Comment at: include/algorithm:3216
+};
+#endif  // _LIBCPP_STD_VER >= 11
+
----------------
If you know a better metaprogramming trick to do this, would be great.
================
Comment at: include/algorithm:4106
+    }
+};
+
----------------
We are not allowed (by default) to use C++11 for this file? A simple lambda would do this much better.
================
Comment at: include/algorithm:4119
 {
-    typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
-    difference_type __len = _VSTD::distance(__first, __last);
-    while (__len != 0)
-    {
-        difference_type __l2 = __len / 2;
-        _ForwardIterator __m = __first;
-        _VSTD::advance(__m, __l2);
-        if (__comp(*__m, __value_))
-        {
-            __first = ++__m;
-            __len -= __l2 + 1;
-        }
-        else
-            __len = __l2;
-    }
-    return __first;
+    return _VSTD::partition_point(__first, __last, __less_than<_ForwardIterator>(__comp, __value_));
 }
----------------
Code duplication between partition_point, lower_bound and upper_bound doesn't seem to have any practical value.
================
Comment at: include/algorithm:4167
+    }
+};
+
----------------
Do you know of a good way to remove code duplication? Move common parts into a base class?
Repository:
  rCXX libc++
https://reviews.llvm.org/D52697
    
    
More information about the libcxx-commits
mailing list