Skip to content

Commit a4cb1c8

Browse files
Abseil Teamahedberg
Abseil Team
authored andcommitted
Export of internal Abseil changes.
-- 6fdf24a197b964f9bacbebd0ceca305aef1654fc by Shaindel Schwartz <shaindel@google.com>: Internal change PiperOrigin-RevId: 231627312 -- 65f7faf52bff01384171efb85fee159378dedf70 by CJ Johnson <johnsoncj@google.com>: Relocates the definitions of the InputIterator-accepting parts of the InlinedVector API into the top-level. The removed functions had no other callers so there was no reason to keep the layer of indirection in the form of the function call. PiperOrigin-RevId: 231527459 -- 30e105b749b5ecc50fdaf26c7da589617efce425 by CJ Johnson <johnsoncj@google.com>: Relocates closing brace for absl namespace in InlinedVector to the correct end location PiperOrigin-RevId: 231477871 -- 063c1e8b9d1f032662c46d574e20ecc357b87d0c by Eric Fiselier <ericwf@google.com>: Cleanup std::hash probing metafunctions. Previously there were two different ways to probe for std::hash. One in hash.h and another in type_traits.h, and they were both implemented differently, and neither correctly worked around bad STL implementations. This patch unifies the implementations into a single IsHashable trait. It also: * Correctly checks for old libc++ versions where this won't work. * Avoids undefined behavior which resulted from calling std::is_constructible incomplete types. * Unifies the feature test macro used in the headers and the tests. Additionally it also slightly changes the behavior of when absl::variant is hashable. Previously we disable hashing when std::hash<T>()(key) was formed but when std::hash<T> couldn't be destructed. This seems wrong. If a user provides a evil specialization of std::hash, then it's OK for variant's hash to blow up. PiperOrigin-RevId: 231468345 -- 05d75dd4b07c893de9b104731644d0d207b01253 by Abseil Team <absl-team@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 231397518 -- a0ee9032f9e04039f3410ed17fcf45ae1a3868f5 by CJ Johnson <johnsoncj@google.com>: Remove unused EnableIfAtLeastInputIterator from InlinedVector PiperOrigin-RevId: 231348903 -- 4dcd4e9a6780a81d7a6974c7bf22a037e6482b49 by Abseil Team <absl-team@google.com>: Remove unnecessary register keyword from absl/base/internal/endian.h. PiperOrigin-RevId: 231316570 -- c8584836caa3a10f90a8604a85d4b831310b72ee by Abseil Team <absl-team@google.com>: Fix hashtablez_sampler compilation on older Android NDK builds PiperOrigin-RevId: 231283542 GitOrigin-RevId: 6fdf24a197b964f9bacbebd0ceca305aef1654fc Change-Id: I185b12fb8347e3ad0ffcb2cbb83a53450e5eb938
1 parent 540e253 commit a4cb1c8

File tree

13 files changed

+435
-118
lines changed

13 files changed

+435
-118
lines changed

absl/base/internal/endian.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ inline uint64_t gbswap_64(uint64_t host_int) {
7575
if (__builtin_constant_p(host_int)) {
7676
return __bswap_constant_64(host_int);
7777
} else {
78-
register uint64_t result;
78+
uint64_t result;
7979
__asm__("bswap %0" : "=r"(result) : "0"(host_int));
8080
return result;
8181
}

absl/base/macros.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
// This code is compiled directly on many platforms, including client
2525
// platforms like Windows, Mac, and embedded systems. Before making
2626
// any changes here, make sure that you're not breaking any platforms.
27-
//
2827

2928
#ifndef ABSL_BASE_MACROS_H_
3029
#define ABSL_BASE_MACROS_H_

absl/container/inlined_vector.h

Lines changed: 15 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,11 @@ class InlinedVector {
7171
return static_cast<typename A::size_type>(N);
7272
}
7373

74-
template <typename Iterator>
75-
using IsAtLeastInputIterator = std::is_convertible<
76-
typename std::iterator_traits<Iterator>::iterator_category,
77-
std::input_iterator_tag>;
78-
7974
template <typename Iterator>
8075
using IsAtLeastForwardIterator = std::is_convertible<
8176
typename std::iterator_traits<Iterator>::iterator_category,
8277
std::forward_iterator_tag>;
8378

84-
template <typename Iterator>
85-
using EnableIfAtLeastInputIterator =
86-
absl::enable_if_t<IsAtLeastInputIterator<Iterator>::value>;
87-
8879
template <typename Iterator>
8980
using EnableIfAtLeastForwardIterator =
9081
absl::enable_if_t<IsAtLeastForwardIterator<Iterator>::value>;
@@ -163,7 +154,7 @@ class InlinedVector {
163154
InlinedVector(InputIterator first, InputIterator last,
164155
const allocator_type& alloc = allocator_type())
165156
: allocator_and_tag_(alloc) {
166-
AppendInputRange(first, last);
157+
std::copy(first, last, std::back_inserter(*this));
167158
}
168159

169160
// Creates a copy of `other` using `other`'s allocator.
@@ -534,7 +525,13 @@ class InlinedVector {
534525
template <typename InputIterator,
535526
DisableIfAtLeastForwardIterator<InputIterator>* = nullptr>
536527
void assign(InputIterator first, InputIterator last) {
537-
AssignInputRange(first, last);
528+
size_type assign_index = 0;
529+
for (; (assign_index < size()) && (first != last);
530+
static_cast<void>(++assign_index), static_cast<void>(++first)) {
531+
*(data() + assign_index) = *first;
532+
}
533+
erase(data() + assign_index, data() + size());
534+
std::copy(first, last, std::back_inserter(*this));
538535
}
539536

540537
// `InlinedVector::resize()`
@@ -630,7 +627,12 @@ class InlinedVector {
630627
template <typename InputIterator,
631628
DisableIfAtLeastForwardIterator<InputIterator>* = nullptr>
632629
iterator insert(const_iterator pos, InputIterator first, InputIterator last) {
633-
return InsertWithInputRange(pos, first, last);
630+
size_type initial_insert_index = std::distance(cbegin(), pos);
631+
for (size_type insert_index = initial_insert_index; first != last;
632+
static_cast<void>(++insert_index), static_cast<void>(++first)) {
633+
insert(data() + insert_index, *first);
634+
}
635+
return iterator(data() + initial_insert_index);
634636
}
635637

636638
// `InlinedVector::emplace()`
@@ -1131,20 +1133,6 @@ class InlinedVector {
11311133
}
11321134
}
11331135

1134-
template <typename InputIterator>
1135-
void AssignInputRange(InputIterator first, InputIterator last) {
1136-
static_assert(IsAtLeastInputIterator<InputIterator>::value, "");
1137-
1138-
// Optimized to avoid reallocation.
1139-
// Prefer reassignment to copy construction for elements.
1140-
iterator out = begin();
1141-
for (; first != last && out != end(); ++first, ++out) {
1142-
*out = *first;
1143-
}
1144-
erase(out, end());
1145-
std::copy(first, last, std::back_inserter(*this));
1146-
}
1147-
11481136
template <typename ForwardIterator>
11491137
void AppendForwardRange(ForwardIterator first, ForwardIterator last) {
11501138
static_assert(IsAtLeastForwardIterator<ForwardIterator>::value, "");
@@ -1160,13 +1148,6 @@ class InlinedVector {
11601148
}
11611149
}
11621150

1163-
template <typename InputIterator>
1164-
void AppendInputRange(InputIterator first, InputIterator last) {
1165-
static_assert(IsAtLeastInputIterator<InputIterator>::value, "");
1166-
1167-
std::copy(first, last, std::back_inserter(*this));
1168-
}
1169-
11701151
iterator InsertWithCount(const_iterator position, size_type n,
11711152
const_reference v) {
11721153
assert(position >= begin() && position <= end());
@@ -1198,18 +1179,6 @@ class InlinedVector {
11981179
return it_pair.first;
11991180
}
12001181

1201-
template <typename InputIterator>
1202-
iterator InsertWithInputRange(const_iterator position, InputIterator first,
1203-
InputIterator last) {
1204-
static_assert(IsAtLeastInputIterator<InputIterator>::value, "");
1205-
assert(position >= begin() && position <= end());
1206-
1207-
size_type index = position - cbegin();
1208-
size_type i = index;
1209-
while (first != last) insert(begin() + i++, *first++);
1210-
return begin() + index;
1211-
}
1212-
12131182
void SwapImpl(InlinedVector& other) {
12141183
using std::swap; // Augment ADL with `std::swap`.
12151184

@@ -1393,13 +1362,12 @@ auto AbslHashValue(H h, const InlinedVector<TheT, TheN, TheA>& v) -> H {
13931362
auto n = v.size();
13941363
return H::combine(H::combine_contiguous(std::move(h), p, n), n);
13951364
}
1365+
} // namespace absl
13961366

13971367
// -----------------------------------------------------------------------------
13981368
// Implementation of InlinedVector
13991369
//
14001370
// Do not depend on any below implementation details!
14011371
// -----------------------------------------------------------------------------
14021372

1403-
} // namespace absl
1404-
14051373
#endif // ABSL_CONTAINER_INLINED_VECTOR_H_

absl/container/internal/hashtablez_sampler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int64_t GetGeometricVariable(int64_t mean) {
9393
// under piii debug for some binaries.
9494
double q = static_cast<uint32_t>(rng >> (prng_mod_power - 26)) + 1.0;
9595
// Put the computed p-value through the CDF of a geometric.
96-
double interval = (std::log2(q) - 26) * (-std::log(2.0) * mean);
96+
double interval = (log2(q) - 26) * (-std::log(2.0) * mean);
9797

9898
// Very large values of interval overflow int64_t. If we happen to
9999
// hit such improbable condition, we simply cheat and clamp interval

0 commit comments

Comments
 (0)