summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2019-01-28 12:10:41 -0800
committerGravatar Ashley Hedberg <ahedberg@google.com>2019-01-28 15:59:07 -0500
commit540e2537b92cd4abfae6ceddfe24304345461f32 (patch)
treed12760ad683360fab4c112c9fb7464fe02374d39
parent89ea0c5ff34aaa5855cfc7aa41f323b8a0ef0ede (diff)
Export of internal Abseil changes.
-- 8c420997e7a08b9e7e24afa32d6e37cb2bfa2c12 by Abseil Team <absl-team@google.com>: Import of CCTZ from GitHub. PiperOrigin-RevId: 231265916 -- f52b9e201698b315c23ebaa6c8ec97362048d9b8 by CJ Johnson <johnsoncj@google.com>: inlined_capacity() => GetInlinedCapacity() Originally I intended inlined_capacity() to be moved from the private to public part of the API eventually so I named it appropriately and punted on publicizing it until later. After it was found to cause an issue on some platforms, I decided there was no reason to grow the API of the type just for a pretty function name. Thus, this change brings its name to be of the same format as the rest of the Abseil team's naming convention. PiperOrigin-RevId: 231248856 -- 04e700ea1aad12cdb6a1ed29e183c59d97a47ccd by Abseil Team <absl-team@google.com>: Merge https://github.com/abseil/abseil-cpp/pull/255 PiperOrigin-RevId: 231240011 -- 4f2c2212c98093194c73572995e7770b58c9b9a0 by CJ Johnson <johnsoncj@google.com>: Adds identifiers to the AbslHashValue(...) forward declaration bringing it in line with the format of the other forward declarations while keeping it on one line. PiperOrigin-RevId: 231231932 -- 68923d6c9289eb523126638f25d95916456125cf by CJ Johnson <johnsoncj@google.com>: Remove bad calls to assert(...) that do not make sense PiperOrigin-RevId: 231214093 -- a2a0b59b7dc2c39aca979ff6e474b9e170ab96b6 by CJ Johnson <johnsoncj@google.com>: Switch to trailing return type syntax for non-member functions of InlinedVector PiperOrigin-RevId: 230975981 GitOrigin-RevId: 8c420997e7a08b9e7e24afa32d6e37cb2bfa2c12 Change-Id: Ibbad7f27b596801bc770b440afed8d5e9e89ff8d
-rw-r--r--absl/container/inlined_vector.h65
-rw-r--r--absl/time/internal/cctz/src/time_zone_format.cc2
-rw-r--r--absl/time/internal/cctz/src/time_zone_info.cc4
-rw-r--r--absl/time/internal/cctz/src/time_zone_libc.cc8
4 files changed, 38 insertions, 41 deletions
diff --git a/absl/container/inlined_vector.h b/absl/container/inlined_vector.h
index 6c67862e..e0f1714c 100644
--- a/absl/container/inlined_vector.h
+++ b/absl/container/inlined_vector.h
@@ -67,7 +67,7 @@ namespace absl {
template <typename T, size_t N, typename A = std::allocator<T>>
class InlinedVector {
static_assert(N > 0, "InlinedVector requires inline capacity greater than 0");
- constexpr static typename A::size_type inlined_capacity() {
+ constexpr static typename A::size_type GetInlinedCapacity() {
return static_cast<typename A::size_type>(N);
}
@@ -275,12 +275,12 @@ class InlinedVector {
// Returns the number of elements that can be stored in the inlined vector
// without requiring a reallocation of underlying memory.
//
- // NOTE: For most inlined vectors, `capacity()` should equal
- // `inlined_capacity()`. For inlined vectors which exceed this capacity, they
+ // NOTE: For most inlined vectors, `capacity()` should equal the template
+ // parameter `N`. For inlined vectors which exceed this capacity, they
// will no longer be inlined and `capacity()` will equal its capacity on the
// allocated heap.
size_type capacity() const noexcept {
- return allocated() ? allocation().capacity() : inlined_capacity();
+ return allocated() ? allocation().capacity() : GetInlinedCapacity();
}
// `InlinedVector::data()`
@@ -667,12 +667,9 @@ class InlinedVector {
template <typename... Args>
reference emplace_back(Args&&... args) {
size_type s = size();
- assert(s <= capacity());
if (ABSL_PREDICT_FALSE(s == capacity())) {
return GrowAndEmplaceBack(std::forward<Args>(args)...);
}
- assert(s < capacity());
-
pointer space;
if (allocated()) {
tag().set_allocated_size(s + 1);
@@ -790,19 +787,19 @@ class InlinedVector {
// `InlinedVector::shrink_to_fit()`
//
// Reduces memory usage by freeing unused memory. After this call, calls to
- // `capacity()` will be equal to `(std::max)(inlined_capacity(), size())`.
+ // `capacity()` will be equal to `(std::max)(GetInlinedCapacity(), size())`.
//
- // If `size() <= inlined_capacity()` and the elements are currently stored on
- // the heap, they will be moved to the inlined storage and the heap memory
+ // If `size() <= GetInlinedCapacity()` and the elements are currently stored
+ // on the heap, they will be moved to the inlined storage and the heap memory
// will be deallocated.
//
- // If `size() > inlined_capacity()` and `size() < capacity()` the elements
+ // If `size() > GetInlinedCapacity()` and `size() < capacity()` the elements
// will be moved to a smaller heap allocation.
void shrink_to_fit() {
const auto s = size();
if (ABSL_PREDICT_FALSE(!allocated() || s == capacity())) return;
- if (s <= inlined_capacity()) {
+ if (s <= GetInlinedCapacity()) {
// Move the elements to the inlined storage.
// We have to do this using a temporary, because `inlined_storage` and
// `allocation_storage` are in a union field.
@@ -833,7 +830,7 @@ class InlinedVector {
private:
template <typename H, typename TheT, size_t TheN, typename TheA>
- friend H AbslHashValue(H, const InlinedVector<TheT, TheN, TheA>& vector);
+ friend auto AbslHashValue(H h, const InlinedVector<TheT, TheN, TheA>& v) -> H;
// Holds whether the vector is allocated or not in the lowest bit and the size
// in the high bits:
@@ -984,7 +981,7 @@ class InlinedVector {
const size_type s = size();
assert(s <= capacity());
- size_type target = (std::max)(inlined_capacity(), s + delta);
+ size_type target = (std::max)(GetInlinedCapacity(), s + delta);
// Compute new capacity by repeatedly doubling current capacity
// TODO(psrc): Check and avoid overflow?
@@ -1087,7 +1084,7 @@ class InlinedVector {
}
void InitAssign(size_type n) {
- if (n > inlined_capacity()) {
+ if (n > GetInlinedCapacity()) {
Allocation new_allocation(allocator(), n);
init_allocation(new_allocation);
UninitializedFill(allocated_space(), allocated_space() + n);
@@ -1099,7 +1096,7 @@ class InlinedVector {
}
void InitAssign(size_type n, const_reference v) {
- if (n > inlined_capacity()) {
+ if (n > GetInlinedCapacity()) {
Allocation new_allocation(allocator(), n);
init_allocation(new_allocation);
UninitializedFill(allocated_space(), allocated_space() + n, v);
@@ -1323,8 +1320,8 @@ class InlinedVector {
// Swaps the contents of two inlined vectors. This convenience function
// simply calls `InlinedVector::swap()`.
template <typename T, size_t N, typename A>
-void swap(InlinedVector<T, N, A>& a,
- InlinedVector<T, N, A>& b) noexcept(noexcept(a.swap(b))) {
+auto swap(InlinedVector<T, N, A>& a,
+ InlinedVector<T, N, A>& b) noexcept(noexcept(a.swap(b))) -> void {
a.swap(b);
}
@@ -1332,8 +1329,8 @@ void swap(InlinedVector<T, N, A>& a,
//
// Tests the equivalency of the contents of two inlined vectors.
template <typename T, size_t N, typename A>
-bool operator==(const InlinedVector<T, N, A>& a,
- const InlinedVector<T, N, A>& b) {
+auto operator==(const InlinedVector<T, N, A>& a,
+ const InlinedVector<T, N, A>& b) -> bool {
return absl::equal(a.begin(), a.end(), b.begin(), b.end());
}
@@ -1341,8 +1338,8 @@ bool operator==(const InlinedVector<T, N, A>& a,
//
// Tests the inequality of the contents of two inlined vectors.
template <typename T, size_t N, typename A>
-bool operator!=(const InlinedVector<T, N, A>& a,
- const InlinedVector<T, N, A>& b) {
+auto operator!=(const InlinedVector<T, N, A>& a,
+ const InlinedVector<T, N, A>& b) -> bool {
return !(a == b);
}
@@ -1351,8 +1348,8 @@ bool operator!=(const InlinedVector<T, N, A>& a,
// Tests whether the contents of one inlined vector are less than the contents
// of another through a lexicographical comparison operation.
template <typename T, size_t N, typename A>
-bool operator<(const InlinedVector<T, N, A>& a,
- const InlinedVector<T, N, A>& b) {
+auto operator<(const InlinedVector<T, N, A>& a, const InlinedVector<T, N, A>& b)
+ -> bool {
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
}
@@ -1361,8 +1358,8 @@ bool operator<(const InlinedVector<T, N, A>& a,
// Tests whether the contents of one inlined vector are greater than the
// contents of another through a lexicographical comparison operation.
template <typename T, size_t N, typename A>
-bool operator>(const InlinedVector<T, N, A>& a,
- const InlinedVector<T, N, A>& b) {
+auto operator>(const InlinedVector<T, N, A>& a, const InlinedVector<T, N, A>& b)
+ -> bool {
return b < a;
}
@@ -1371,8 +1368,8 @@ bool operator>(const InlinedVector<T, N, A>& a,
// Tests whether the contents of one inlined vector are less than or equal to
// the contents of another through a lexicographical comparison operation.
template <typename T, size_t N, typename A>
-bool operator<=(const InlinedVector<T, N, A>& a,
- const InlinedVector<T, N, A>& b) {
+auto operator<=(const InlinedVector<T, N, A>& a,
+ const InlinedVector<T, N, A>& b) -> bool {
return !(b < a);
}
@@ -1381,8 +1378,8 @@ bool operator<=(const InlinedVector<T, N, A>& a,
// Tests whether the contents of one inlined vector are greater than or equal to
// the contents of another through a lexicographical comparison operation.
template <typename T, size_t N, typename A>
-bool operator>=(const InlinedVector<T, N, A>& a,
- const InlinedVector<T, N, A>& b) {
+auto operator>=(const InlinedVector<T, N, A>& a,
+ const InlinedVector<T, N, A>& b) -> bool {
return !(a < b);
}
@@ -1391,10 +1388,10 @@ bool operator>=(const InlinedVector<T, N, A>& a,
// Provides `absl::Hash` support for inlined vectors. You do not normally call
// this function directly.
template <typename H, typename TheT, size_t TheN, typename TheA>
-H AbslHashValue(H hash, const InlinedVector<TheT, TheN, TheA>& vector) {
- auto p = vector.data();
- auto n = vector.size();
- return H::combine(H::combine_contiguous(std::move(hash), p, n), n);
+auto AbslHashValue(H h, const InlinedVector<TheT, TheN, TheA>& v) -> H {
+ auto p = v.data();
+ auto n = v.size();
+ return H::combine(H::combine_contiguous(std::move(h), p, n), n);
}
// -----------------------------------------------------------------------------
diff --git a/absl/time/internal/cctz/src/time_zone_format.cc b/absl/time/internal/cctz/src/time_zone_format.cc
index aad52c27..a5c72df8 100644
--- a/absl/time/internal/cctz/src/time_zone_format.cc
+++ b/absl/time/internal/cctz/src/time_zone_format.cc
@@ -13,7 +13,7 @@
// limitations under the License.
#if !defined(HAS_STRPTIME)
-# if !defined(_MSC_VER)
+# if !defined(_MSC_VER) && !defined(__MINGW32__)
# define HAS_STRPTIME 1 // assume everyone has strptime() except windows
# endif
#endif
diff --git a/absl/time/internal/cctz/src/time_zone_info.cc b/absl/time/internal/cctz/src/time_zone_info.cc
index 2cb358d0..6aa80ff6 100644
--- a/absl/time/internal/cctz/src/time_zone_info.cc
+++ b/absl/time/internal/cctz/src/time_zone_info.cc
@@ -921,7 +921,7 @@ bool TimeZoneInfo::NextTransition(const time_point<seconds>& tp,
++begin;
}
std::int_fast64_t unix_time = ToUnixSeconds(tp);
- const Transition target = { unix_time };
+ const Transition target = {unix_time, 0, civil_second(), civil_second()};
const Transition* tr = std::upper_bound(begin, end, target,
Transition::ByUnixTime());
for (; tr != end; ++tr) { // skip no-op transitions
@@ -956,7 +956,7 @@ bool TimeZoneInfo::PrevTransition(const time_point<seconds>& tp,
}
unix_time += 1; // ceils
}
- const Transition target = { unix_time };
+ const Transition target = {unix_time, 0, civil_second(), civil_second()};
const Transition* tr = std::lower_bound(begin, end, target,
Transition::ByUnixTime());
for (; tr != begin; --tr) { // skip no-op transitions
diff --git a/absl/time/internal/cctz/src/time_zone_libc.cc b/absl/time/internal/cctz/src/time_zone_libc.cc
index 6db519e1..28291708 100644
--- a/absl/time/internal/cctz/src/time_zone_libc.cc
+++ b/absl/time/internal/cctz/src/time_zone_libc.cc
@@ -267,13 +267,13 @@ time_zone::civil_lookup TimeZoneLibC::MakeTime(const civil_second& cs) const {
return {time_zone::civil_lookup::UNIQUE, tp, tp, tp};
}
-bool TimeZoneLibC::NextTransition(const time_point<seconds>& tp,
- time_zone::civil_transition* trans) const {
+bool TimeZoneLibC::NextTransition(const time_point<seconds>&,
+ time_zone::civil_transition*) const {
return false;
}
-bool TimeZoneLibC::PrevTransition(const time_point<seconds>& tp,
- time_zone::civil_transition* trans) const {
+bool TimeZoneLibC::PrevTransition(const time_point<seconds>&,
+ time_zone::civil_transition*) const {
return false;
}