From 52acfe6fc6b8bb9b1b7854993dd0fb33f0f3c4af Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 14 Dec 2020 08:53:54 -0800 Subject: Export of internal Abseil changes -- 751781aa5b9e998f84a8a7e00789c80d3338730e by Abseil Team : Fix attributes.h compilation with -Wundef flag in C PiperOrigin-RevId: 347394915 -- 66070a8166b0e1a61236b954d07fbb378f4f990b by Abseil Team : Revert the usage of variant<> in Cord iterator and reader. The introduction of the variant may lead to some missed compiler optimizations. PiperOrigin-RevId: 347384869 GitOrigin-RevId: 751781aa5b9e998f84a8a7e00789c80d3338730e Change-Id: Ibf1190d498a6f968f2ea9b89467ccfb5224dafa8 --- absl/base/attributes.h | 2 +- absl/strings/BUILD.bazel | 1 - absl/strings/CMakeLists.txt | 1 - absl/strings/cord.cc | 11 ++++------- absl/strings/cord.h | 20 +++++++++----------- 5 files changed, 14 insertions(+), 21 deletions(-) (limited to 'absl') diff --git a/absl/base/attributes.h b/absl/base/attributes.h index f1d3cfe4..0ba1e7da 100644 --- a/absl/base/attributes.h +++ b/absl/base/attributes.h @@ -646,7 +646,7 @@ // Every usage of a deprecated entity will trigger a warning when compiled with // clang's `-Wdeprecated-declarations` option. This option is turned off by // default, but the warnings will be reported by clang-tidy. -#if defined(__clang__) && __cplusplus >= 201103L +#if defined(__clang__) && defined(__cplusplus) && __cplusplus >= 201103L #define ABSL_DEPRECATED(message) __attribute__((deprecated(message))) #endif diff --git a/absl/strings/BUILD.bazel b/absl/strings/BUILD.bazel index aab3a286..3154d80d 100644 --- a/absl/strings/BUILD.bazel +++ b/absl/strings/BUILD.bazel @@ -311,7 +311,6 @@ cc_library( "//absl/functional:function_ref", "//absl/meta:type_traits", "//absl/types:optional", - "//absl/types:variant", ], ) diff --git a/absl/strings/CMakeLists.txt b/absl/strings/CMakeLists.txt index 6cdab257..fa61ff61 100644 --- a/absl/strings/CMakeLists.txt +++ b/absl/strings/CMakeLists.txt @@ -571,7 +571,6 @@ absl_cc_library( absl::function_ref absl::inlined_vector absl::optional - absl::variant absl::raw_logging_internal absl::strings absl::strings_internal diff --git a/absl/strings/cord.cc b/absl/strings/cord.cc index f87f4882..8d51c750 100644 --- a/absl/strings/cord.cc +++ b/absl/strings/cord.cc @@ -1299,8 +1299,7 @@ void Cord::CopyToArraySlowPath(char* dst) const { } Cord::ChunkIterator& Cord::ChunkIterator::AdvanceStack() { - assert(absl::holds_alternative(context_)); - auto& stack_of_right_children = absl::get(context_); + auto& stack_of_right_children = stack_of_right_children_; if (stack_of_right_children.empty()) { assert(!current_chunk_.empty()); // Called on invalid iterator. // We have reached the end of the Cord. @@ -1357,8 +1356,7 @@ Cord Cord::ChunkIterator::AdvanceAndReadBytes(size_t n) { } return subcord; } - assert(absl::holds_alternative(context_)); - auto& stack_of_right_children = absl::get(context_); + auto& stack_of_right_children = stack_of_right_children_; if (n < current_chunk_.size()) { // Range to read is a proper subrange of the current chunk. assert(current_leaf_ != nullptr); @@ -1461,7 +1459,7 @@ void Cord::ChunkIterator::AdvanceBytesSlowPath(size_t n) { n -= current_chunk_.size(); bytes_remaining_ -= current_chunk_.size(); - if (!absl::holds_alternative(context_)) { + if (stack_of_right_children_.empty()) { // We have reached the end of the Cord. assert(bytes_remaining_ == 0); return; @@ -1470,8 +1468,7 @@ void Cord::ChunkIterator::AdvanceBytesSlowPath(size_t n) { // Process the next node(s) on the stack, skipping whole subtrees depending on // their length and how many bytes we are advancing. CordRep* node = nullptr; - assert(absl::holds_alternative(context_)); - auto& stack_of_right_children = absl::get(context_); + auto& stack_of_right_children = stack_of_right_children_; while (!stack_of_right_children.empty()) { node = stack_of_right_children.back(); stack_of_right_children.pop_back(); diff --git a/absl/strings/cord.h b/absl/strings/cord.h index 5fc61a73..7136f034 100644 --- a/absl/strings/cord.h +++ b/absl/strings/cord.h @@ -82,7 +82,6 @@ #include "absl/strings/internal/string_constant.h" #include "absl/strings/string_view.h" #include "absl/types/optional.h" -#include "absl/types/variant.h" namespace absl { ABSL_NAMESPACE_BEGIN @@ -362,7 +361,11 @@ class Cord { friend class CharIterator; private: - using Stack = absl::InlinedVector; + // Stack of right children of concat nodes that we have to visit. + // Keep this at the end of the structure to avoid cache-thrashing. + // TODO(jgm): Benchmark to see if there's a more optimal value than 47 for + // the inlined vector size (47 exists for backward compatibility). + using Stack = absl::InlinedVector; // Constructs a `begin()` iterator from `cord`. explicit ChunkIterator(const Cord* cord); @@ -389,10 +392,8 @@ class Cord { absl::cord_internal::CordRep* current_leaf_ = nullptr; // The number of bytes left in the `Cord` over which we are iterating. size_t bytes_remaining_ = 0; - // Context of this chunk iterator, can be one of: - // - monostate: iterator holds only one chunk or is empty. - // - Stack : iterator holds a concat / substring tree - absl::variant context_; + // See 'Stack' alias definition. + Stack stack_of_right_children_; }; // Cord::ChunkIterator::chunk_begin() @@ -1108,8 +1109,7 @@ inline Cord::ChunkIterator::ChunkIterator(const Cord* cord) : bytes_remaining_(cord->size()) { if (cord->empty()) return; if (cord->contents_.is_tree()) { - Stack& stack_of_right_children = context_.emplace(); - stack_of_right_children.push_back(cord->contents_.tree()); + stack_of_right_children_.push_back(cord->contents_.tree()); operator++(); } else { current_chunk_ = absl::string_view(cord->contents_.data(), cord->size()); @@ -1122,9 +1122,7 @@ inline Cord::ChunkIterator& Cord::ChunkIterator::operator++() { assert(bytes_remaining_ >= current_chunk_.size()); bytes_remaining_ -= current_chunk_.size(); if (bytes_remaining_ > 0) { - if (absl::holds_alternative(context_)) { - return AdvanceStack(); - } + return AdvanceStack(); } else { current_chunk_ = {}; } -- cgit v1.2.3