From: Mike Aizatsky Date: Fri, 18 Nov 2016 20:48:52 +0000 (+0000) Subject: rename InternalBinarySearch to InternalLowerBound X-Git-Tag: llvmorg-4.0.0-rc1~4160 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7594ec3355cf4410663868a119a5ffb05649e095;p=platform%2Fupstream%2Fllvm.git rename InternalBinarySearch to InternalLowerBound Summary: The new name better corresponds to its logic. Reviewers: kcc Subscribers: kubabrecka Differential Revision: https://reviews.llvm.org/D26821 llvm-svn: 287377 --- diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 63956ae..499bc07 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -637,9 +637,9 @@ void InternalSort(Container *v, uptr size, Compare comp) { // Works like std::lower_bound: finds the first element that is not less // than the val. -template -uptr InternalBinarySearch(const Container &v, uptr first, uptr last, - const Value &val, Compare comp) { +template +uptr InternalLowerBound(const Container &v, uptr first, uptr last, + const Value &val, Compare comp) { while (last > first) { uptr mid = (first + last) / 2; if (comp(v[mid], val)) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc index 2ec7a82..214dda5 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cc @@ -153,8 +153,8 @@ StackTrace StackDepotReverseMap::Get(u32 id) { if (!map_.size()) return StackTrace(); IdDescPair pair = {id, nullptr}; - uptr idx = InternalBinarySearch(map_, 0, map_.size(), pair, - IdDescPair::IdComparator); + uptr idx = + InternalLowerBound(map_, 0, map_.size(), pair, IdDescPair::IdComparator); if (idx > map_.size() || map_[idx].id != id) return StackTrace(); return map_[idx].desc->load(); diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cc index 0980cf4..ebc885d 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_common_test.cc @@ -172,7 +172,7 @@ bool UptrLess(uptr a, uptr b) { return a < b; } -TEST(SanitizerCommon, InternalBinarySearch) { +TEST(SanitizerCommon, InternalLowerBound) { static const uptr kSize = 5; int arr[kSize]; arr[0] = 1; @@ -181,22 +181,22 @@ TEST(SanitizerCommon, InternalBinarySearch) { arr[3] = 7; arr[4] = 11; - EXPECT_EQ(0u, InternalBinarySearch(arr, 0, kSize, 0, UptrLess)); - EXPECT_EQ(0u, InternalBinarySearch(arr, 0, kSize, 1, UptrLess)); - EXPECT_EQ(1u, InternalBinarySearch(arr, 0, kSize, 2, UptrLess)); - EXPECT_EQ(1u, InternalBinarySearch(arr, 0, kSize, 3, UptrLess)); - EXPECT_EQ(2u, InternalBinarySearch(arr, 0, kSize, 4, UptrLess)); - EXPECT_EQ(2u, InternalBinarySearch(arr, 0, kSize, 5, UptrLess)); - EXPECT_EQ(3u, InternalBinarySearch(arr, 0, kSize, 6, UptrLess)); - EXPECT_EQ(3u, InternalBinarySearch(arr, 0, kSize, 7, UptrLess)); - EXPECT_EQ(4u, InternalBinarySearch(arr, 0, kSize, 8, UptrLess)); - EXPECT_EQ(4u, InternalBinarySearch(arr, 0, kSize, 9, UptrLess)); - EXPECT_EQ(4u, InternalBinarySearch(arr, 0, kSize, 10, UptrLess)); - EXPECT_EQ(4u, InternalBinarySearch(arr, 0, kSize, 11, UptrLess)); - EXPECT_EQ(5u, InternalBinarySearch(arr, 0, kSize, 12, UptrLess)); + EXPECT_EQ(0u, InternalLowerBound(arr, 0, kSize, 0, UptrLess)); + EXPECT_EQ(0u, InternalLowerBound(arr, 0, kSize, 1, UptrLess)); + EXPECT_EQ(1u, InternalLowerBound(arr, 0, kSize, 2, UptrLess)); + EXPECT_EQ(1u, InternalLowerBound(arr, 0, kSize, 3, UptrLess)); + EXPECT_EQ(2u, InternalLowerBound(arr, 0, kSize, 4, UptrLess)); + EXPECT_EQ(2u, InternalLowerBound(arr, 0, kSize, 5, UptrLess)); + EXPECT_EQ(3u, InternalLowerBound(arr, 0, kSize, 6, UptrLess)); + EXPECT_EQ(3u, InternalLowerBound(arr, 0, kSize, 7, UptrLess)); + EXPECT_EQ(4u, InternalLowerBound(arr, 0, kSize, 8, UptrLess)); + EXPECT_EQ(4u, InternalLowerBound(arr, 0, kSize, 9, UptrLess)); + EXPECT_EQ(4u, InternalLowerBound(arr, 0, kSize, 10, UptrLess)); + EXPECT_EQ(4u, InternalLowerBound(arr, 0, kSize, 11, UptrLess)); + EXPECT_EQ(5u, InternalLowerBound(arr, 0, kSize, 12, UptrLess)); } -TEST(SanitizerCommon, InternalBinarySearchVsLowerBound) { +TEST(SanitizerCommon, InternalLowerBoundVsStdLowerBound) { std::vector data; auto create_item = [] (size_t i, size_t j) { auto v = i * 10000 + j; @@ -215,8 +215,8 @@ TEST(SanitizerCommon, InternalBinarySearchVsLowerBound) { for (auto to_find : {val - 1, val, val + 1}) { uptr expected = std::lower_bound(data.begin(), data.end(), to_find) - data.begin(); - EXPECT_EQ(expected, InternalBinarySearch(data.data(), 0, data.size(), - to_find, std::less())); + EXPECT_EQ(expected, InternalLowerBound(data.data(), 0, data.size(), + to_find, std::less())); } } }