diff options
author | Abseil Team <absl-team@google.com> | 2021-01-21 12:04:50 -0800 |
---|---|---|
committer | vslashg <gfalcon@google.com> | 2021-01-21 15:32:08 -0500 |
commit | 3a2d6572d06709da32a17f053ca1e3c8e2af90df (patch) | |
tree | 91a3261c35d04c4b2b912e60f1630a3f2b75ad3b /absl/strings/cord.h | |
parent | 22771d471930ce88e1e75d0ca9dd8c65a7b0f895 (diff) |
Export of internal Abseil changes
--
3b43586da865534cf86401d2cae09c65c60b8474 by Abseil Team <absl-team@google.com>:
Introduce CordRepRingReader class
PiperOrigin-RevId: 353070937
--
0bff6e4bcca34fdd1e6610da5fb3c37fd49b2940 by Abseil Team <absl-team@google.com>:
Fix docstring typo "Exmaple" -> "Example"
PiperOrigin-RevId: 352927688
--
1ef4e0a1100cfa7bc9d9e8f155acf0e469348b56 by Abseil Team <absl-team@google.com>:
Refactor tree initialization of ChunkIterator and CordReader
PiperOrigin-RevId: 352916786
--
919c3eb175b87294184a405785eef4fab520d47e by Abseil Team <absl-team@google.com>:
Disable `preserve_most` when compiling with sanitizers.
PiperOrigin-RevId: 352890630
GitOrigin-RevId: 3b43586da865534cf86401d2cae09c65c60b8474
Change-Id: I8a733494b353af69a46862a4019a7f9b40148f49
Diffstat (limited to 'absl/strings/cord.h')
-rw-r--r-- | absl/strings/cord.h | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/absl/strings/cord.h b/absl/strings/cord.h index 9d8764a0..abef98fe 100644 --- a/absl/strings/cord.h +++ b/absl/strings/cord.h @@ -367,9 +367,15 @@ class Cord { // the inlined vector size (47 exists for backward compatibility). using Stack = absl::InlinedVector<absl::cord_internal::CordRep*, 47>; + // Constructs a `begin()` iterator from `tree`. `tree` must not be null. + explicit ChunkIterator(cord_internal::CordRep* tree); + // Constructs a `begin()` iterator from `cord`. explicit ChunkIterator(const Cord* cord); + // Initializes this instance from a tree. Invoked by constructors. + void InitTree(cord_internal::CordRep* tree); + // Removes `n` bytes from `current_chunk_`. Expects `n` to be smaller than // `current_chunk_.size()`. void RemoveChunkPrefix(size_t n); @@ -1100,11 +1106,20 @@ inline bool Cord::StartsWith(absl::string_view rhs) const { return EqualsImpl(rhs, rhs_size); } +inline void Cord::ChunkIterator::InitTree(cord_internal::CordRep* tree) { + stack_of_right_children_.push_back(tree); + operator++(); +} + +inline Cord::ChunkIterator::ChunkIterator(cord_internal::CordRep* tree) + : bytes_remaining_(tree->length) { + InitTree(tree); +} + inline Cord::ChunkIterator::ChunkIterator(const Cord* cord) : bytes_remaining_(cord->size()) { if (cord->contents_.is_tree()) { - stack_of_right_children_.push_back(cord->contents_.as_tree()); - operator++(); + InitTree(cord->contents_.as_tree()); } else { current_chunk_ = absl::string_view(cord->contents_.data(), bytes_remaining_); @@ -1155,6 +1170,7 @@ inline void Cord::ChunkIterator::RemoveChunkPrefix(size_t n) { } inline void Cord::ChunkIterator::AdvanceBytes(size_t n) { + assert(bytes_remaining_ >= n); if (ABSL_PREDICT_TRUE(n < current_chunk_.size())) { RemoveChunkPrefix(n); } else if (n != 0) { |