summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
Diffstat (limited to 'absl')
-rw-r--r--absl/container/BUILD.bazel1
-rw-r--r--absl/container/CMakeLists.txt1
-rw-r--r--absl/container/internal/raw_hash_set.cc2
-rw-r--r--absl/container/internal/raw_hash_set.h53
-rw-r--r--absl/flags/internal/usage.cc17
-rw-r--r--absl/flags/internal/usage_test.cc3
-rw-r--r--absl/types/span.h2
-rw-r--r--absl/types/span_test.cc2
8 files changed, 37 insertions, 44 deletions
diff --git a/absl/container/BUILD.bazel b/absl/container/BUILD.bazel
index f22fdc60..cf55f4bb 100644
--- a/absl/container/BUILD.bazel
+++ b/absl/container/BUILD.bazel
@@ -598,7 +598,6 @@ cc_library(
":hashtable_debug_hooks",
":hashtablez_sampler",
":have_sse",
- ":layout",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/base:endian",
diff --git a/absl/container/CMakeLists.txt b/absl/container/CMakeLists.txt
index 91c40154..691a05c0 100644
--- a/absl/container/CMakeLists.txt
+++ b/absl/container/CMakeLists.txt
@@ -666,7 +666,6 @@ absl_cc_library(
absl::hash_policy_traits
absl::hashtable_debug_hooks
absl::have_sse
- absl::layout
absl::memory
absl::meta
absl::optional
diff --git a/absl/container/internal/raw_hash_set.cc b/absl/container/internal/raw_hash_set.cc
index e219956f..3c72c41a 100644
--- a/absl/container/internal/raw_hash_set.cc
+++ b/absl/container/internal/raw_hash_set.cc
@@ -23,7 +23,7 @@ namespace absl {
ABSL_NAMESPACE_BEGIN
namespace container_internal {
-ABSL_CONST_INIT ABSL_DLL alignas(16) const ctrl_t kEmptyGroup[16] = {
+alignas(16) ABSL_CONST_INIT ABSL_DLL const ctrl_t kEmptyGroup[16] = {
ctrl_t::kSentinel, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty,
ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty,
ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty, ctrl_t::kEmpty,
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h
index bafafd46..ade2f584 100644
--- a/absl/container/internal/raw_hash_set.h
+++ b/absl/container/internal/raw_hash_set.h
@@ -112,7 +112,6 @@
#include "absl/container/internal/hashtable_debug_hooks.h"
#include "absl/container/internal/hashtablez_sampler.h"
#include "absl/container/internal/have_sse.h"
-#include "absl/container/internal/layout.h"
#include "absl/memory/memory.h"
#include "absl/meta/type_traits.h"
#include "absl/numeric/bits.h"
@@ -625,6 +624,20 @@ inline void SetCtrl(size_t i, h2_t h, size_t capacity, ctrl_t* ctrl,
SetCtrl(i, static_cast<ctrl_t>(h), capacity, ctrl, slot, slot_size);
}
+// The allocated block consists of `capacity + 1 + NumClonedBytes()` control
+// bytes followed by `capacity` slots, which must be aligned to `slot_align`.
+// SlotOffset returns the offset of the slots into the allocated block.
+inline size_t SlotOffset(size_t capacity, size_t slot_align) {
+ assert(IsValidCapacity(capacity));
+ const size_t num_control_bytes = capacity + 1 + NumClonedBytes();
+ return (num_control_bytes + slot_align - 1) & (~slot_align + 1);
+}
+
+// Returns the size of the allocated block. See also above comment.
+inline size_t AllocSize(size_t capacity, size_t slot_size, size_t slot_align) {
+ return SlotOffset(capacity, slot_align) + capacity * slot_size;
+}
+
// Policy: a policy defines how to perform different operations on
// the slots of the hashtable (see hash_policy_traits.h for the full interface
// of policy).
@@ -681,15 +694,6 @@ class raw_hash_set {
auto KeyTypeCanBeHashed(const Hash& h, const key_type& k) -> decltype(h(k));
auto KeyTypeCanBeEq(const Eq& eq, const key_type& k) -> decltype(eq(k, k));
- using Layout = absl::container_internal::Layout<ctrl_t, slot_type>;
-
- static Layout MakeLayout(size_t capacity) {
- assert(IsValidCapacity(capacity));
- // The extra control bytes are for 1 sentinel byte followed by
- // NumClonedBytes() bytes that are cloned from the beginning.
- return Layout(capacity + 1 + NumClonedBytes(), capacity);
- }
-
using AllocTraits = absl::allocator_traits<allocator_type>;
using SlotAlloc = typename absl::allocator_traits<
allocator_type>::template rebind_alloc<slot_type>;
@@ -1610,11 +1614,12 @@ class raw_hash_set {
infoz() = Sample();
}
- auto layout = MakeLayout(capacity_);
- char* mem = static_cast<char*>(
- Allocate<Layout::Alignment()>(&alloc_ref(), layout.AllocSize()));
- ctrl_ = layout.template Pointer<0>(mem);
- slots_ = layout.template Pointer<1>(mem);
+ char* mem = static_cast<char*>(Allocate<alignof(slot_type)>(
+ &alloc_ref(),
+ AllocSize(capacity_, sizeof(slot_type), alignof(slot_type))));
+ ctrl_ = reinterpret_cast<ctrl_t*>(mem);
+ slots_ = reinterpret_cast<slot_type*>(
+ mem + SlotOffset(capacity_, alignof(slot_type)));
ResetCtrl(capacity_, ctrl_, slots_, sizeof(slot_type));
reset_growth_left();
infoz().RecordStorageChanged(size_, capacity_);
@@ -1627,10 +1632,11 @@ class raw_hash_set {
PolicyTraits::destroy(&alloc_ref(), slots_ + i);
}
}
- auto layout = MakeLayout(capacity_);
// Unpoison before returning the memory to the allocator.
SanitizerUnpoisonMemoryRegion(slots_, sizeof(slot_type) * capacity_);
- Deallocate<Layout::Alignment()>(&alloc_ref(), ctrl_, layout.AllocSize());
+ Deallocate<alignof(slot_type)>(
+ &alloc_ref(), ctrl_,
+ AllocSize(capacity_, sizeof(slot_type), alignof(slot_type)));
ctrl_ = EmptyGroup();
slots_ = nullptr;
size_ = 0;
@@ -1661,9 +1667,9 @@ class raw_hash_set {
if (old_capacity) {
SanitizerUnpoisonMemoryRegion(old_slots,
sizeof(slot_type) * old_capacity);
- auto layout = MakeLayout(old_capacity);
- Deallocate<Layout::Alignment()>(&alloc_ref(), old_ctrl,
- layout.AllocSize());
+ Deallocate<alignof(slot_type)>(
+ &alloc_ref(), old_ctrl,
+ AllocSize(old_capacity, sizeof(slot_type), alignof(slot_type)));
}
infoz().RecordRehash(total_probe_length);
}
@@ -1948,8 +1954,7 @@ struct HashtableDebugAccess<Set, absl::void_t<typename Set::raw_hash_set>> {
static size_t AllocatedByteSize(const Set& c) {
size_t capacity = c.capacity_;
if (capacity == 0) return 0;
- auto layout = Set::MakeLayout(capacity);
- size_t m = layout.AllocSize();
+ size_t m = AllocSize(capacity, sizeof(Slot), alignof(Slot));
size_t per_slot = Traits::space_used(static_cast<const Slot*>(nullptr));
if (per_slot != ~size_t{}) {
@@ -1967,8 +1972,8 @@ struct HashtableDebugAccess<Set, absl::void_t<typename Set::raw_hash_set>> {
static size_t LowerBoundAllocatedByteSize(size_t size) {
size_t capacity = GrowthToLowerboundCapacity(size);
if (capacity == 0) return 0;
- auto layout = Set::MakeLayout(NormalizeCapacity(capacity));
- size_t m = layout.AllocSize();
+ size_t m =
+ AllocSize(NormalizeCapacity(capacity), sizeof(Slot), alignof(Slot));
size_t per_slot = Traits::space_used(static_cast<const Slot*>(nullptr));
if (per_slot != ~size_t{}) {
m += per_slot * size;
diff --git a/absl/flags/internal/usage.cc b/absl/flags/internal/usage.cc
index a883567f..949709e8 100644
--- a/absl/flags/internal/usage.cc
+++ b/absl/flags/internal/usage.cc
@@ -17,7 +17,6 @@
#include <stdint.h>
-#include <algorithm>
#include <functional>
#include <map>
#include <ostream>
@@ -256,6 +255,9 @@ void FlagsHelpImpl(std::ostream& out, PerFlagFilter filter_cb,
matching_flags;
flags_internal::ForEachFlag([&](absl::CommandLineFlag& flag) {
+ // Ignore retired flags.
+ if (flag.IsRetired()) return;
+
// If the flag has been stripped, pretend that it doesn't exist.
if (flag.Help() == flags_internal::kStrippedFlagHelp) return;
@@ -273,14 +275,6 @@ void FlagsHelpImpl(std::ostream& out, PerFlagFilter filter_cb,
absl::string_view file_separator; // controls blank lines between files
for (auto& package : matching_flags) {
if (format == HelpFormat::kHumanReadable) {
- // Hide packages with only retired flags
- bool all_package_flags_are_retired = true;
- for (const auto& flags_in_file : package.second) {
- for (const auto* flag : flags_in_file.second) {
- all_package_flags_are_retired &= flag->IsRetired();
- }
- }
- if (all_package_flags_are_retired) continue;
out << package_separator;
package_separator = "\n\n";
}
@@ -340,11 +334,8 @@ void FlagsHelpImpl(std::ostream& out,
// Produces the help message describing specific flag.
void FlagHelp(std::ostream& out, const CommandLineFlag& flag,
HelpFormat format) {
- if (format == HelpFormat::kHumanReadable) {
- // Ignore retired flags
- if (flag.IsRetired()) return;
+ if (format == HelpFormat::kHumanReadable)
flags_internal::FlagHelpHumanReadable(flag, out);
- }
}
// --------------------------------------------------------------------
diff --git a/absl/flags/internal/usage_test.cc b/absl/flags/internal/usage_test.cc
index 5055640a..044d71c8 100644
--- a/absl/flags/internal/usage_test.cc
+++ b/absl/flags/internal/usage_test.cc
@@ -61,9 +61,6 @@ ABSL_FLAG(
"Even more long long long long long long long long long long long long "
"help message.");
-ABSL_RETIRED_FLAG(int64_t, usage_reporting_test_flag_07, 1,
- "usage_reporting_test_flag_07 help message");
-
namespace {
namespace flags = absl::flags_internal;
diff --git a/absl/types/span.h b/absl/types/span.h
index 41db3420..6272bb7a 100644
--- a/absl/types/span.h
+++ b/absl/types/span.h
@@ -40,7 +40,6 @@
// * `absl::Span` has compiler-provided move and copy constructors and
// assignment. This is due to them being specified as `constexpr`, but that
// implies const in C++11.
-// * `absl::Span` has no `element_type` typedef
// * A read-only `absl::Span<const T>` can be implicitly constructed from an
// initializer list.
// * `absl::Span` has no `bytes()`, `size_bytes()`, `as_bytes()`, or
@@ -170,6 +169,7 @@ class Span {
typename std::enable_if<!std::is_const<T>::value, U>::type;
public:
+ using element_type = T;
using value_type = absl::remove_cv_t<T>;
using pointer = T*;
using const_pointer = const T*;
diff --git a/absl/types/span_test.cc b/absl/types/span_test.cc
index 2584339b..13264aae 100644
--- a/absl/types/span_test.cc
+++ b/absl/types/span_test.cc
@@ -661,6 +661,8 @@ TEST(IntSpan, ExposesContainerTypesAndConsts) {
CheckType<absl::Span<int>::const_reverse_iterator>(slice.crend());
testing::StaticAssertTypeEq<int, absl::Span<int>::value_type>();
testing::StaticAssertTypeEq<int, absl::Span<const int>::value_type>();
+ testing::StaticAssertTypeEq<int, absl::Span<int>::element_type>();
+ testing::StaticAssertTypeEq<const int, absl::Span<const int>::element_type>();
testing::StaticAssertTypeEq<int*, absl::Span<int>::pointer>();
testing::StaticAssertTypeEq<const int*, absl::Span<const int>::pointer>();
testing::StaticAssertTypeEq<int&, absl::Span<int>::reference>();