diff --git a/absl/base/BUILD.bazel b/absl/base/BUILD.bazel index 16b0e2f..65ff0dd 100644 --- a/absl/base/BUILD.bazel +++ b/absl/base/BUILD.bazel
@@ -56,7 +56,6 @@ srcs = ["log_severity.cc"], hdrs = ["log_severity.h"], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":config", @@ -160,7 +159,6 @@ "internal/low_level_alloc.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = select({ "//absl:msvc_compiler": [], "//absl:clang-cl_compiler": [], @@ -222,7 +220,6 @@ "internal/unscaledcycleclock.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = select({ "//absl:msvc_compiler": [ "-DEFAULTLIB:advapi32.lib", @@ -293,7 +290,6 @@ srcs = ["internal/throw_delegate.cc"], hdrs = ["internal/throw_delegate.h"], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__", @@ -713,7 +709,6 @@ srcs = ["internal/strerror.cc"], hdrs = ["internal/strerror.h"], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__",
diff --git a/absl/base/internal/exponential_biased.cc b/absl/base/internal/exponential_biased.cc index 1b30c06..05aeea5 100644 --- a/absl/base/internal/exponential_biased.cc +++ b/absl/base/internal/exponential_biased.cc
@@ -64,7 +64,7 @@ // Assume huge values are bias neutral, retain bias for next call. return std::numeric_limits<int64_t>::max() / 2; } - double value = std::round(interval); + double value = std::rint(interval); bias_ = interval - value; return value; }
diff --git a/absl/base/internal/exponential_biased.h b/absl/base/internal/exponential_biased.h index 94f79a3..a81f10e 100644 --- a/absl/base/internal/exponential_biased.h +++ b/absl/base/internal/exponential_biased.h
@@ -66,7 +66,7 @@ // Adjusting with rounding bias is relatively trivial: // // double value = bias_ + exponential_distribution(mean)(); -// double rounded_value = std::round(value); +// double rounded_value = std::rint(value); // bias_ = value - rounded_value; // return rounded_value; //
diff --git a/absl/container/BUILD.bazel b/absl/container/BUILD.bazel index 9651054..f22fdc6 100644 --- a/absl/container/BUILD.bazel +++ b/absl/container/BUILD.bazel
@@ -505,7 +505,6 @@ ], hdrs = ["internal/hashtablez_sampler.h"], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":have_sse",
diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h index 508f212..03f199a 100644 --- a/absl/container/internal/raw_hash_set.h +++ b/absl/container/internal/raw_hash_set.h
@@ -502,6 +502,22 @@ return growth + static_cast<size_t>((static_cast<int64_t>(growth) - 1) / 7); } +template <class InputIter> +size_t SelectBucketCountForIterRange(InputIter first, InputIter last, + size_t bucket_count) { + if (bucket_count != 0) { + return bucket_count; + } + using InputIterCategory = + typename std::iterator_traits<InputIter>::iterator_category; + if (std::is_base_of<std::random_access_iterator_tag, + InputIterCategory>::value) { + return GrowthToLowerboundCapacity( + static_cast<size_t>(std::distance(first, last))); + } + return 0; +} + inline void AssertIsFull(ctrl_t* ctrl) { ABSL_HARDENING_ASSERT((ctrl != nullptr && IsFull(*ctrl)) && "Invalid operation on iterator. The element might have " @@ -820,7 +836,8 @@ raw_hash_set(InputIter first, InputIter last, size_t bucket_count = 0, const hasher& hash = hasher(), const key_equal& eq = key_equal(), const allocator_type& alloc = allocator_type()) - : raw_hash_set(bucket_count, hash, eq, alloc) { + : raw_hash_set(SelectBucketCountForIterRange(first, last, bucket_count), + hash, eq, alloc) { insert(first, last); }
diff --git a/absl/container/internal/raw_hash_set_benchmark.cc b/absl/container/internal/raw_hash_set_benchmark.cc index f9be2c5..977ff4c 100644 --- a/absl/container/internal/raw_hash_set_benchmark.cc +++ b/absl/container/internal/raw_hash_set_benchmark.cc
@@ -254,6 +254,23 @@ } BENCHMARK(BM_CopyAssign)->Range(128, 4096); +void BM_RangeCtor(benchmark::State& state) { + std::random_device rd; + std::mt19937 rng(rd()); + std::uniform_int_distribution<uint64_t> dist(0, ~uint64_t{}); + std::vector<int> values; + const size_t desired_size = state.range(0); + while (values.size() < desired_size) { + values.emplace_back(dist(rng)); + } + + for (auto unused : state) { + IntTable t{values.begin(), values.end()}; + benchmark::DoNotOptimize(t); + } +} +BENCHMARK(BM_RangeCtor)->Range(128, 65536); + void BM_NoOpReserveIntTable(benchmark::State& state) { IntTable t; t.reserve(100000); @@ -378,6 +395,12 @@ return table->find(key) != table->end(); } +auto CodegenAbslRawHashSetInt64Insert(absl::container_internal::IntTable* table, + int64_t key) + -> decltype(table->insert(key)) { + return table->insert(key); +} + bool CodegenAbslRawHashSetInt64Contains( absl::container_internal::IntTable* table, int64_t key) { return table->contains(key); @@ -391,6 +414,7 @@ int odr = (::benchmark::DoNotOptimize(std::make_tuple( &CodegenAbslRawHashSetInt64Find, &CodegenAbslRawHashSetInt64FindNeEnd, + &CodegenAbslRawHashSetInt64Insert, &CodegenAbslRawHashSetInt64Contains, &CodegenAbslRawHashSetInt64Iterate)), 1);
diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc index 87cbdfc..a191bff 100644 --- a/absl/container/internal/raw_hash_set_test.cc +++ b/absl/container/internal/raw_hash_set_test.cc
@@ -627,28 +627,53 @@ } int decompose_constructed; +int decompose_copy_constructed; +int decompose_copy_assigned; +int decompose_move_constructed; +int decompose_move_assigned; struct DecomposeType { - DecomposeType(int i) : i(i) { // NOLINT + DecomposeType(int i = 0) : i(i) { // NOLINT ++decompose_constructed; } explicit DecomposeType(const char* d) : DecomposeType(*d) {} + DecomposeType(const DecomposeType& other) : i(other.i) { + ++decompose_copy_constructed; + } + DecomposeType& operator=(const DecomposeType& other) { + ++decompose_copy_assigned; + i = other.i; + return *this; + } + DecomposeType(DecomposeType&& other) : i(other.i) { + ++decompose_move_constructed; + } + DecomposeType& operator=(DecomposeType&& other) { + ++decompose_move_assigned; + i = other.i; + return *this; + } + int i; }; struct DecomposeHash { using is_transparent = void; - size_t operator()(DecomposeType a) const { return a.i; } + size_t operator()(const DecomposeType& a) const { return a.i; } size_t operator()(int a) const { return a; } size_t operator()(const char* a) const { return *a; } }; struct DecomposeEq { using is_transparent = void; - bool operator()(DecomposeType a, DecomposeType b) const { return a.i == b.i; } - bool operator()(DecomposeType a, int b) const { return a.i == b; } - bool operator()(DecomposeType a, const char* b) const { return a.i == *b; } + bool operator()(const DecomposeType& a, const DecomposeType& b) const { + return a.i == b.i; + } + bool operator()(const DecomposeType& a, int b) const { return a.i == b; } + bool operator()(const DecomposeType& a, const char* b) const { + return a.i == *b; + } }; struct DecomposePolicy { @@ -658,9 +683,9 @@ template <typename T> static void construct(void*, DecomposeType* slot, T&& v) { - *slot = DecomposeType(std::forward<T>(v)); + ::new (slot) DecomposeType(std::forward<T>(v)); } - static void destroy(void*, DecomposeType*) {} + static void destroy(void*, DecomposeType* slot) { slot->~DecomposeType(); } static DecomposeType& element(slot_type* slot) { return *slot; } template <class F, class T> @@ -675,8 +700,13 @@ const int one = 1; const char* three_p = "3"; const auto& three = three_p; + const int elem_vector_count = 256; + std::vector<DecomposeType> elem_vector(elem_vector_count, DecomposeType{0}); + std::iota(elem_vector.begin(), elem_vector.end(), 0); - raw_hash_set<DecomposePolicy, Hash, Eq, std::allocator<int>> set1; + using DecomposeSet = + raw_hash_set<DecomposePolicy, Hash, Eq, std::allocator<int>>; + DecomposeSet set1; decompose_constructed = 0; int expected_constructed = 0; @@ -734,20 +764,72 @@ expected_constructed += construct_three; EXPECT_EQ(expected_constructed, decompose_constructed); } + + decompose_copy_constructed = 0; + decompose_copy_assigned = 0; + decompose_move_constructed = 0; + decompose_move_assigned = 0; + int expected_copy_constructed = 0; + int expected_move_constructed = 0; + { // raw_hash_set(first, last) with random-access iterators + DecomposeSet set2(elem_vector.begin(), elem_vector.end()); + // Expect exactly one copy-constructor call for each element if no + // rehashing is done. + expected_copy_constructed += elem_vector_count; + EXPECT_EQ(expected_copy_constructed, decompose_copy_constructed); + EXPECT_EQ(expected_move_constructed, decompose_move_constructed); + EXPECT_EQ(0, decompose_move_assigned); + EXPECT_EQ(0, decompose_copy_assigned); + } + + { // raw_hash_set(first, last) with forward iterators + std::list<DecomposeType> elem_list(elem_vector.begin(), elem_vector.end()); + expected_copy_constructed = decompose_copy_constructed; + DecomposeSet set2(elem_list.begin(), elem_list.end()); + // Expect exactly N elements copied into set, expect at most 2*N elements + // moving internally for all resizing needed (for a growth factor of 2). + expected_copy_constructed += elem_vector_count; + EXPECT_EQ(expected_copy_constructed, decompose_copy_constructed); + expected_move_constructed += elem_vector_count; + EXPECT_LT(expected_move_constructed, decompose_move_constructed); + expected_move_constructed += elem_vector_count; + EXPECT_GE(expected_move_constructed, decompose_move_constructed); + EXPECT_EQ(0, decompose_move_assigned); + EXPECT_EQ(0, decompose_copy_assigned); + expected_copy_constructed = decompose_copy_constructed; + expected_move_constructed = decompose_move_constructed; + } + + { // insert(first, last) + DecomposeSet set2; + set2.insert(elem_vector.begin(), elem_vector.end()); + // Expect exactly N elements copied into set, expect at most 2*N elements + // moving internally for all resizing needed (for a growth factor of 2). + const int expected_new_elements = elem_vector_count; + const int expected_max_element_moves = 2 * elem_vector_count; + expected_copy_constructed += expected_new_elements; + EXPECT_EQ(expected_copy_constructed, decompose_copy_constructed); + expected_move_constructed += expected_max_element_moves; + EXPECT_GE(expected_move_constructed, decompose_move_constructed); + EXPECT_EQ(0, decompose_move_assigned); + EXPECT_EQ(0, decompose_copy_assigned); + expected_copy_constructed = decompose_copy_constructed; + expected_move_constructed = decompose_move_constructed; + } } TEST(Table, Decompose) { TestDecompose<DecomposeHash, DecomposeEq>(false); struct TransparentHashIntOverload { - size_t operator()(DecomposeType a) const { return a.i; } + size_t operator()(const DecomposeType& a) const { return a.i; } size_t operator()(int a) const { return a; } }; struct TransparentEqIntOverload { - bool operator()(DecomposeType a, DecomposeType b) const { + bool operator()(const DecomposeType& a, const DecomposeType& b) const { return a.i == b.i; } - bool operator()(DecomposeType a, int b) const { return a.i == b; } + bool operator()(const DecomposeType& a, int b) const { return a.i == b; } }; TestDecompose<TransparentHashIntOverload, DecomposeEq>(true); TestDecompose<TransparentHashIntOverload, TransparentEqIntOverload>(true);
diff --git a/absl/flags/BUILD.bazel b/absl/flags/BUILD.bazel index 940e356..c178b86 100644 --- a/absl/flags/BUILD.bazel +++ b/absl/flags/BUILD.bazel
@@ -51,7 +51,6 @@ "internal/program_name.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl/flags:__pkg__", @@ -75,7 +74,6 @@ "usage_config.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":path_util", @@ -96,7 +94,6 @@ "marshalling.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base:config", @@ -116,7 +113,6 @@ "internal/commandlineflag.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base:config", @@ -133,7 +129,6 @@ "commandlineflag.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":commandlineflag_internal", @@ -175,7 +170,6 @@ "reflection.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":commandlineflag", @@ -200,7 +194,6 @@ "internal/sequence_lock.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, visibility = ["//absl/base:__subpackages__"], deps = [ @@ -251,7 +244,6 @@ "internal/usage.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl/flags:__pkg__", @@ -281,7 +273,6 @@ "usage.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":usage_internal", @@ -300,7 +291,6 @@ "parse.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":commandlineflag",
diff --git a/absl/hash/BUILD.bazel b/absl/hash/BUILD.bazel index f5005a0..4b2c220 100644 --- a/absl/hash/BUILD.bazel +++ b/absl/hash/BUILD.bazel
@@ -34,7 +34,6 @@ ], hdrs = ["hash.h"], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":city",
diff --git a/absl/numeric/BUILD.bazel b/absl/numeric/BUILD.bazel index a0ef905..ea587bf 100644 --- a/absl/numeric/BUILD.bazel +++ b/absl/numeric/BUILD.bazel
@@ -62,7 +62,6 @@ ], hdrs = ["int128.h"], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ ":bits",
diff --git a/absl/status/BUILD.bazel b/absl/status/BUILD.bazel index 4db72c0..189bd73 100644 --- a/absl/status/BUILD.bazel +++ b/absl/status/BUILD.bazel
@@ -40,7 +40,6 @@ "status_payload_printer.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], deps = [ "//absl/base:atomic_hook", "//absl/base:config", @@ -77,7 +76,6 @@ "statusor.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], deps = [ ":status", "//absl/base:core_headers",
diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index a02ee39..1cb5b3e 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel
@@ -66,7 +66,6 @@ "substitute.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], deps = [ ":internal", "//absl/base", @@ -97,7 +96,6 @@ "internal/utf8.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], deps = [ "//absl/base:config", "//absl/base:core_headers", @@ -280,7 +278,6 @@ "internal/cord_rep_ring_reader.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], visibility = [ "//visibility:private", ], @@ -330,7 +327,6 @@ "cord.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], deps = [ ":cord_internal", ":cordz_functions", @@ -359,7 +355,6 @@ srcs = ["internal/cordz_handle.cc"], hdrs = ["internal/cordz_handle.h"], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], visibility = [ "//absl:__subpackages__", ], @@ -376,7 +371,6 @@ srcs = ["internal/cordz_info.cc"], hdrs = ["internal/cordz_info.h"], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], visibility = [ "//absl:__subpackages__", ], @@ -1001,7 +995,6 @@ "internal/str_format/parser.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], visibility = ["//visibility:private"], deps = [ ":strings",
diff --git a/absl/synchronization/BUILD.bazel b/absl/synchronization/BUILD.bazel index 46c4b91..92e2448 100644 --- a/absl/synchronization/BUILD.bazel +++ b/absl/synchronization/BUILD.bazel
@@ -36,7 +36,6 @@ "internal/graphcycles.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, visibility = [ "//absl:__subpackages__", @@ -88,7 +87,6 @@ "notification.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = select({ "//absl:msvc_compiler": [], "//absl:clang-cl_compiler": [],
diff --git a/absl/time/BUILD.bazel b/absl/time/BUILD.bazel index 4700616..3e25ca2 100644 --- a/absl/time/BUILD.bazel +++ b/absl/time/BUILD.bazel
@@ -43,7 +43,6 @@ "time.h", ], copts = ABSL_DEFAULT_COPTS, - features = ["-no_undefined"], linkopts = ABSL_DEFAULT_LINKOPTS, deps = [ "//absl/base",
diff --git a/absl/time/internal/cctz/BUILD.bazel b/absl/time/internal/cctz/BUILD.bazel index 35747e5..45a9529 100644 --- a/absl/time/internal/cctz/BUILD.bazel +++ b/absl/time/internal/cctz/BUILD.bazel
@@ -45,7 +45,6 @@ hdrs = [ "include/cctz/civil_time.h", ], - features = ["-no_undefined"], textual_hdrs = ["include/cctz/civil_time_detail.h"], visibility = ["//visibility:public"], deps = ["//absl/base:config"], @@ -75,7 +74,6 @@ "include/cctz/time_zone.h", "include/cctz/zone_info_source.h", ], - features = ["-no_undefined"], linkopts = select({ ":osx": [ "-framework Foundation",