Export of internal Abseil changes.
-- 1224e58a45e4d016b18f5a6cf5762ba33027017a by CJ Johnson <johnsoncj@google.com>: Unifies the growth factor of InlinedVector's mutating members to max(2 * capacity, req_capacity). In doing so, LegacyNextCapacityFrom(...) is removed thus removing a loop from several callsites. PiperOrigin-RevId: 259920301 -- 945fc0bf27b67ea77d39144dcb6a483dc879ceda by Laramie Leavitt <lar@google.com>: Cleanup header guards which do not reflect the correct style. PiperOrigin-RevId: 259881520 -- 8c7d0532ba9a9aabfd57f67552572b2b1bedda97 by Derek Mauro <dmauro@google.com>: Move log_severity sources to the new log_severity target. PiperOrigin-RevId: 259837015 GitOrigin-RevId: 1224e58a45e4d016b18f5a6cf5762ba33027017a Change-Id: Id19506c3b8db71a0d4391ee917bfef3e802d550d
This commit is contained in:
parent
ad1485c898
commit
36d37ab992
8 changed files with 72 additions and 48 deletions
|
@ -39,8 +39,11 @@ cc_library(
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "log_severity",
|
name = "log_severity",
|
||||||
|
srcs = ["log_severity.cc"],
|
||||||
|
hdrs = ["log_severity.h"],
|
||||||
copts = ABSL_DEFAULT_COPTS,
|
copts = ABSL_DEFAULT_COPTS,
|
||||||
linkopts = ABSL_DEFAULT_LINKOPTS,
|
linkopts = ABSL_DEFAULT_LINKOPTS,
|
||||||
|
deps = [":core_headers"],
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
|
@ -154,7 +157,6 @@ cc_library(
|
||||||
"internal/sysinfo.cc",
|
"internal/sysinfo.cc",
|
||||||
"internal/thread_identity.cc",
|
"internal/thread_identity.cc",
|
||||||
"internal/unscaledcycleclock.cc",
|
"internal/unscaledcycleclock.cc",
|
||||||
"log_severity.cc",
|
|
||||||
],
|
],
|
||||||
hdrs = [
|
hdrs = [
|
||||||
"call_once.h",
|
"call_once.h",
|
||||||
|
@ -168,7 +170,6 @@ cc_library(
|
||||||
"internal/thread_identity.h",
|
"internal/thread_identity.h",
|
||||||
"internal/tsan_mutex_interface.h",
|
"internal/tsan_mutex_interface.h",
|
||||||
"internal/unscaledcycleclock.h",
|
"internal/unscaledcycleclock.h",
|
||||||
"log_severity.h",
|
|
||||||
],
|
],
|
||||||
copts = ABSL_DEFAULT_COPTS,
|
copts = ABSL_DEFAULT_COPTS,
|
||||||
linkopts = select({
|
linkopts = select({
|
||||||
|
|
|
@ -26,6 +26,12 @@ absl_cc_library(
|
||||||
absl_cc_library(
|
absl_cc_library(
|
||||||
NAME
|
NAME
|
||||||
log_severity
|
log_severity
|
||||||
|
HDRS
|
||||||
|
"log_severity.h"
|
||||||
|
SRCS
|
||||||
|
"log_severity.cc"
|
||||||
|
DEPS
|
||||||
|
absl::core_headers
|
||||||
COPTS
|
COPTS
|
||||||
${ABSL_DEFAULT_COPTS}
|
${ABSL_DEFAULT_COPTS}
|
||||||
)
|
)
|
||||||
|
@ -154,6 +160,7 @@ absl_cc_library(
|
||||||
absl::config
|
absl::config
|
||||||
absl::core_headers
|
absl::core_headers
|
||||||
absl::dynamic_annotations
|
absl::dynamic_annotations
|
||||||
|
absl::log_severity
|
||||||
absl::spinlock_wait
|
absl::spinlock_wait
|
||||||
absl::type_traits
|
absl::type_traits
|
||||||
Threads::Threads
|
Threads::Threads
|
||||||
|
@ -510,6 +517,7 @@ absl_cc_test(
|
||||||
"log_severity_test.cc"
|
"log_severity_test.cc"
|
||||||
DEPS
|
DEPS
|
||||||
absl::base
|
absl::base
|
||||||
|
absl::log_severity
|
||||||
gmock
|
gmock
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
|
|
|
@ -279,7 +279,7 @@ class InlinedVector {
|
||||||
// allocated heap.
|
// allocated heap.
|
||||||
size_type capacity() const noexcept {
|
size_type capacity() const noexcept {
|
||||||
return storage_.GetIsAllocated() ? storage_.GetAllocatedCapacity()
|
return storage_.GetIsAllocated() ? storage_.GetAllocatedCapacity()
|
||||||
: static_cast<size_type>(N);
|
: storage_.GetInlinedCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
// `InlinedVector::data()`
|
// `InlinedVector::data()`
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#ifndef ABSL_CONTAINER_INTERNAL_INLINED_VECTOR_INTERNAL_H_
|
#ifndef ABSL_CONTAINER_INTERNAL_INLINED_VECTOR_INTERNAL_H_
|
||||||
#define ABSL_CONTAINER_INTERNAL_INLINED_VECTOR_INTERNAL_H_
|
#define ABSL_CONTAINER_INTERNAL_INLINED_VECTOR_INTERNAL_H_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
@ -301,15 +302,17 @@ class Storage {
|
||||||
return data_.allocated.allocated_data;
|
return data_.allocated.allocated_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_type GetInlinedCapacity() const { return static_cast<size_type>(N); }
|
||||||
|
|
||||||
size_type GetAllocatedCapacity() const {
|
size_type GetAllocatedCapacity() const {
|
||||||
return data_.allocated.allocated_capacity;
|
return data_.allocated.allocated_capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageView MakeStorageView() {
|
StorageView MakeStorageView() {
|
||||||
return GetIsAllocated() ? StorageView{GetAllocatedData(), GetSize(),
|
return GetIsAllocated()
|
||||||
|
? StorageView{GetAllocatedData(), GetSize(),
|
||||||
GetAllocatedCapacity()}
|
GetAllocatedCapacity()}
|
||||||
: StorageView{GetInlinedData(), GetSize(),
|
: StorageView{GetInlinedData(), GetSize(), GetInlinedCapacity()};
|
||||||
static_cast<size_type>(N)};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allocator_type* GetAllocPtr() {
|
allocator_type* GetAllocPtr() {
|
||||||
|
@ -402,18 +405,13 @@ class Storage {
|
||||||
return metadata_.template get<1>();
|
return metadata_.template get<1>();
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_type NextCapacityFrom(size_type current_capacity) {
|
static size_type NextCapacity(size_type current_capacity) {
|
||||||
return current_capacity * 2;
|
return current_capacity * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_type LegacyNextCapacityFrom(size_type current_capacity,
|
static size_type ComputeCapacity(size_type current_capacity,
|
||||||
size_type requested_capacity) {
|
size_type requested_capacity) {
|
||||||
// TODO(johnsoncj): Get rid of this old behavior.
|
return (std::max)(NextCapacity(current_capacity), requested_capacity);
|
||||||
size_type new_capacity = current_capacity;
|
|
||||||
while (new_capacity < requested_capacity) {
|
|
||||||
new_capacity *= 2;
|
|
||||||
}
|
|
||||||
return new_capacity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using Metadata =
|
using Metadata =
|
||||||
|
@ -449,13 +447,17 @@ auto Storage<T, N, A>::Initialize(ValueAdapter values, size_type new_size)
|
||||||
|
|
||||||
pointer construct_data;
|
pointer construct_data;
|
||||||
|
|
||||||
if (new_size > static_cast<size_type>(N)) {
|
if (new_size > GetInlinedCapacity()) {
|
||||||
// Because this is only called from the `InlinedVector` constructors, it's
|
// Because this is only called from the `InlinedVector` constructors, it's
|
||||||
// safe to take on the allocation with size `0`. If `ConstructElements(...)`
|
// safe to take on the allocation with size `0`. If `ConstructElements(...)`
|
||||||
// throws, deallocation will be automatically handled by `~Storage()`.
|
// throws, deallocation will be automatically handled by `~Storage()`.
|
||||||
construct_data = AllocatorTraits::allocate(*GetAllocPtr(), new_size);
|
size_type new_capacity = ComputeCapacity(GetInlinedCapacity(), new_size);
|
||||||
SetAllocatedData(construct_data, new_size);
|
pointer new_data = AllocatorTraits::allocate(*GetAllocPtr(), new_capacity);
|
||||||
|
|
||||||
|
SetAllocatedData(new_data, new_capacity);
|
||||||
SetIsAllocated();
|
SetIsAllocated();
|
||||||
|
|
||||||
|
construct_data = new_data;
|
||||||
} else {
|
} else {
|
||||||
construct_data = GetInlinedData();
|
construct_data = GetInlinedData();
|
||||||
}
|
}
|
||||||
|
@ -481,7 +483,10 @@ auto Storage<T, N, A>::Assign(ValueAdapter values, size_type new_size) -> void {
|
||||||
absl::Span<value_type> destroy_loop;
|
absl::Span<value_type> destroy_loop;
|
||||||
|
|
||||||
if (new_size > storage_view.capacity) {
|
if (new_size > storage_view.capacity) {
|
||||||
construct_loop = {allocation_tx.Allocate(new_size), new_size};
|
size_type new_capacity = ComputeCapacity(storage_view.capacity, new_size);
|
||||||
|
pointer new_data = allocation_tx.Allocate(new_capacity);
|
||||||
|
|
||||||
|
construct_loop = {new_data, new_size};
|
||||||
destroy_loop = {storage_view.data, storage_view.size};
|
destroy_loop = {storage_view.data, storage_view.size};
|
||||||
} else if (new_size > storage_view.size) {
|
} else if (new_size > storage_view.size) {
|
||||||
assign_loop = {storage_view.data, storage_view.size};
|
assign_loop = {storage_view.data, storage_view.size};
|
||||||
|
@ -526,8 +531,8 @@ auto Storage<T, N, A>::Resize(ValueAdapter values, size_type new_size) -> void {
|
||||||
absl::Span<value_type> destroy_loop;
|
absl::Span<value_type> destroy_loop;
|
||||||
|
|
||||||
if (new_size > storage_view.capacity) {
|
if (new_size > storage_view.capacity) {
|
||||||
pointer new_data = allocation_tx.Allocate(
|
size_type new_capacity = ComputeCapacity(storage_view.capacity, new_size);
|
||||||
LegacyNextCapacityFrom(storage_view.capacity, new_size));
|
pointer new_data = allocation_tx.Allocate(new_capacity);
|
||||||
|
|
||||||
// Construct new objects in `new_data`
|
// Construct new objects in `new_data`
|
||||||
construct_loop = {new_data + storage_view.size,
|
construct_loop = {new_data + storage_view.size,
|
||||||
|
@ -586,8 +591,8 @@ auto Storage<T, N, A>::Insert(const_iterator pos, ValueAdapter values,
|
||||||
IteratorValueAdapter<MoveIterator> move_values(
|
IteratorValueAdapter<MoveIterator> move_values(
|
||||||
MoveIterator(storage_view.data));
|
MoveIterator(storage_view.data));
|
||||||
|
|
||||||
pointer new_data = allocation_tx.Allocate(
|
size_type new_capacity = ComputeCapacity(storage_view.capacity, new_size);
|
||||||
LegacyNextCapacityFrom(storage_view.capacity, new_size));
|
pointer new_data = allocation_tx.Allocate(new_capacity);
|
||||||
|
|
||||||
construction_tx.Construct(new_data + insert_index, &values, insert_count);
|
construction_tx.Construct(new_data + insert_index, &values, insert_count);
|
||||||
|
|
||||||
|
@ -670,14 +675,20 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference {
|
||||||
IteratorValueAdapter<MoveIterator> move_values(
|
IteratorValueAdapter<MoveIterator> move_values(
|
||||||
MoveIterator(storage_view.data));
|
MoveIterator(storage_view.data));
|
||||||
|
|
||||||
pointer construct_data =
|
pointer construct_data;
|
||||||
(storage_view.size == storage_view.capacity
|
|
||||||
? allocation_tx.Allocate(NextCapacityFrom(storage_view.capacity))
|
|
||||||
: storage_view.data);
|
|
||||||
|
|
||||||
pointer last_ptr = construct_data + storage_view.size;
|
if (storage_view.size == storage_view.capacity) {
|
||||||
AllocatorTraits::construct(*GetAllocPtr(), last_ptr,
|
size_type new_capacity = NextCapacity(storage_view.capacity);
|
||||||
std::forward<Args>(args)...);
|
pointer new_data = allocation_tx.Allocate(new_capacity);
|
||||||
|
|
||||||
|
construct_data = new_data;
|
||||||
|
} else {
|
||||||
|
construct_data = storage_view.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
pointer end = construct_data + storage_view.size;
|
||||||
|
|
||||||
|
AllocatorTraits::construct(*GetAllocPtr(), end, std::forward<Args>(args)...);
|
||||||
|
|
||||||
if (allocation_tx.DidAllocate()) {
|
if (allocation_tx.DidAllocate()) {
|
||||||
ABSL_INTERNAL_TRY {
|
ABSL_INTERNAL_TRY {
|
||||||
|
@ -686,7 +697,7 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference {
|
||||||
storage_view.size);
|
storage_view.size);
|
||||||
}
|
}
|
||||||
ABSL_INTERNAL_CATCH_ANY {
|
ABSL_INTERNAL_CATCH_ANY {
|
||||||
AllocatorTraits::destroy(*GetAllocPtr(), last_ptr);
|
AllocatorTraits::destroy(*GetAllocPtr(), end);
|
||||||
ABSL_INTERNAL_RETHROW;
|
ABSL_INTERNAL_RETHROW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -699,7 +710,7 @@ auto Storage<T, N, A>::EmplaceBack(Args&&... args) -> reference {
|
||||||
}
|
}
|
||||||
|
|
||||||
AddSize(1);
|
AddSize(1);
|
||||||
return *last_ptr;
|
return *end;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, size_t N, typename A>
|
template <typename T, size_t N, typename A>
|
||||||
|
@ -740,8 +751,9 @@ auto Storage<T, N, A>::Reserve(size_type requested_capacity) -> void {
|
||||||
IteratorValueAdapter<MoveIterator> move_values(
|
IteratorValueAdapter<MoveIterator> move_values(
|
||||||
MoveIterator(storage_view.data));
|
MoveIterator(storage_view.data));
|
||||||
|
|
||||||
pointer new_data = allocation_tx.Allocate(
|
size_type new_capacity =
|
||||||
LegacyNextCapacityFrom(storage_view.capacity, requested_capacity));
|
ComputeCapacity(storage_view.capacity, requested_capacity);
|
||||||
|
pointer new_data = allocation_tx.Allocate(new_capacity);
|
||||||
|
|
||||||
inlined_vector_internal::ConstructElements(GetAllocPtr(), new_data,
|
inlined_vector_internal::ConstructElements(GetAllocPtr(), new_data,
|
||||||
&move_values, storage_view.size);
|
&move_values, storage_view.size);
|
||||||
|
@ -762,6 +774,8 @@ auto Storage<T, N, A>::ShrinkToFit() -> void {
|
||||||
StorageView storage_view{GetAllocatedData(), GetSize(),
|
StorageView storage_view{GetAllocatedData(), GetSize(),
|
||||||
GetAllocatedCapacity()};
|
GetAllocatedCapacity()};
|
||||||
|
|
||||||
|
if (ABSL_PREDICT_FALSE(storage_view.size == storage_view.capacity)) return;
|
||||||
|
|
||||||
AllocationTransaction allocation_tx(GetAllocPtr());
|
AllocationTransaction allocation_tx(GetAllocPtr());
|
||||||
|
|
||||||
IteratorValueAdapter<MoveIterator> move_values(
|
IteratorValueAdapter<MoveIterator> move_values(
|
||||||
|
@ -769,12 +783,13 @@ auto Storage<T, N, A>::ShrinkToFit() -> void {
|
||||||
|
|
||||||
pointer construct_data;
|
pointer construct_data;
|
||||||
|
|
||||||
if (storage_view.size <= static_cast<size_type>(N)) {
|
if (storage_view.size > GetInlinedCapacity()) {
|
||||||
construct_data = GetInlinedData();
|
size_type new_capacity = storage_view.size;
|
||||||
} else if (storage_view.size < GetAllocatedCapacity()) {
|
pointer new_data = allocation_tx.Allocate(new_capacity);
|
||||||
construct_data = allocation_tx.Allocate(storage_view.size);
|
|
||||||
|
construct_data = new_data;
|
||||||
} else {
|
} else {
|
||||||
return;
|
construct_data = GetInlinedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
ABSL_INTERNAL_TRY {
|
ABSL_INTERNAL_TRY {
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef ABSL_RANDOM_PCG_ENGINE_H_
|
#ifndef ABSL_RANDOM_INTERNAL_PCG_ENGINE_H_
|
||||||
#define ABSL_RANDOM_PCG_ENGINE_H_
|
#define ABSL_RANDOM_INTERNAL_PCG_ENGINE_H_
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
|
@ -302,4 +302,4 @@ using pcg32_2018_engine = pcg_engine<
|
||||||
} // namespace random_internal
|
} // namespace random_internal
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // ABSL_RANDOM_PCG2018_ENGINE_H_
|
#endif // ABSL_RANDOM_INTERNAL_PCG_ENGINE_H_
|
||||||
|
|
|
@ -26,4 +26,4 @@ bool CPUSupportsRandenHwAes();
|
||||||
} // namespace random_internal
|
} // namespace random_internal
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // ABSL_RANDOM_INTERNAL_RANDEN_FAST_H_
|
#endif // ABSL_RANDOM_INTERNAL_RANDEN_DETECT_H_
|
||||||
|
|
|
@ -43,4 +43,4 @@ bool HasRandenHwAesImplementation();
|
||||||
} // namespace random_internal
|
} // namespace random_internal
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // ABSL_RANDOM_INTERNAL_RANDEN_FAST_H_
|
#endif // ABSL_RANDOM_INTERNAL_RANDEN_HWAES_H_
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
#ifndef ABSL_RANDOM_UNIFORM_HELPER_H_
|
#ifndef ABSL_RANDOM_INTERNAL_UNIFORM_HELPER_H_
|
||||||
#define ABSL_RANDOM_UNIFORM_HELPER_H_
|
#define ABSL_RANDOM_INTERNAL_UNIFORM_HELPER_H_
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
@ -147,4 +147,4 @@ struct UniformDistributionWrapper : public UniformDistribution<NumType> {
|
||||||
} // namespace random_internal
|
} // namespace random_internal
|
||||||
} // namespace absl
|
} // namespace absl
|
||||||
|
|
||||||
#endif // ABSL_RANDOM_UNIFORM_HELPER_H_
|
#endif // ABSL_RANDOM_INTERNAL_UNIFORM_HELPER_H_
|
||||||
|
|
Loading…
Reference in a new issue