diff options
author | Abseil Team <absl-team@google.com> | 2020-12-14 08:53:54 -0800 |
---|---|---|
committer | Mark Barolak <mbar@google.com> | 2020-12-14 13:16:42 -0500 |
commit | 52acfe6fc6b8bb9b1b7854993dd0fb33f0f3c4af (patch) | |
tree | dffd40cf776d2e0e319a1910838a7ee7606958dd /absl/strings/cord.h | |
parent | 1918ad2ae38aa32c74b558b322479a8efdd76363 (diff) |
Export of internal Abseil changes
--
751781aa5b9e998f84a8a7e00789c80d3338730e by Abseil Team <absl-team@google.com>:
Fix attributes.h compilation with -Wundef flag in C
PiperOrigin-RevId: 347394915
--
66070a8166b0e1a61236b954d07fbb378f4f990b by Abseil Team <absl-team@google.com>:
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
Diffstat (limited to 'absl/strings/cord.h')
-rw-r--r-- | absl/strings/cord.h | 20 |
1 files changed, 9 insertions, 11 deletions
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<absl::cord_internal::CordRep*, 4>; + // 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<absl::cord_internal::CordRep*, 47>; // 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<absl::monostate, Stack> 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>(); - 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<Stack>(context_)) { - return AdvanceStack(); - } + return AdvanceStack(); } else { current_chunk_ = {}; } |