about summary refs log tree commit diff
path: root/absl/strings/cord.h
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-03-16T16·06-0700
committervslashg <gfalcon@google.com>2020-03-16T19·11-0400
commit7853a7586c492ce8905c9e49f8679dada6354f2c (patch)
tree987d340989dde52a3ca9e7a5965e119e0241c4c2 /absl/strings/cord.h
parentc6954897f7ece5011f0126db9117361dc1a6ff36 (diff)
Export of internal Abseil changes
--
91ca367a7548270155721bdda74611aeea2a2153 by Abseil Team <absl-team@google.com>:

Replace the only usage of btree_node::swap with simpler logic using transfers and delete btree_node::swap.

Add a benchmark for constructing small containers.

PiperOrigin-RevId: 301169874

--
ff9d73a7125b7f8ab5733cda877204dfbfac138e by Derek Mauro <dmauro@google.com>:

Ensure ABSL_CXX_STANDARD is set.
Fixes #640

PiperOrigin-RevId: 301160106

--
14ca0beee8c109e532134e7e9da7b072da1bf911 by Abseil Team <absl-team@google.com>:

Rollback the change to make Cord iterators a fixed size.  That change increased the iterator size, which can cause a deep recursion call to hit the stack memory limit, in turn causing a signal 11 failure.

PiperOrigin-RevId: 301084915

--
619e3cd9e56408bdb8b3b5a1e08dda1e95242264 by Matthew Brown <matthewbr@google.com>:

Internal Change

PiperOrigin-RevId: 300832828

--
64f8d62ab4c4c78077dbe85a9595a8eeb6d16608 by Gennadiy Rozental <rogeeff@google.com>:

Fix for empty braces support.

We will call proper aggregate construction in case when {} is used as default value. In other words instead of "new T", we'll call "new T{}".

PiperOrigin-RevId: 300715686

--
db3f65594d6db8b104b01262f884dff465b696ef by Abseil Team <absl-team@google.com>:

Emscripten supports thread-local storage nowadays.

PiperOrigin-RevId: 300675185
GitOrigin-RevId: 91ca367a7548270155721bdda74611aeea2a2153
Change-Id: I3344f745f9c3fc78775532b1808442fabd98e34a
Diffstat (limited to 'absl/strings/cord.h')
-rw-r--r--absl/strings/cord.h53
1 files changed, 3 insertions, 50 deletions
diff --git a/absl/strings/cord.h b/absl/strings/cord.h
index eb236e50e22e..66645eef6e48 100644
--- a/absl/strings/cord.h
+++ b/absl/strings/cord.h
@@ -48,6 +48,7 @@
 #include "absl/base/internal/per_thread_tls.h"
 #include "absl/base/macros.h"
 #include "absl/base/port.h"
+#include "absl/container/inlined_vector.h"
 #include "absl/functional/function_ref.h"
 #include "absl/meta/type_traits.h"
 #include "absl/strings/internal/cord_internal.h"
@@ -67,55 +68,6 @@ template <typename H>
 H HashFragmentedCord(H, const Cord&);
 }
 
-namespace cord_internal {
-
-// It's expensive to keep a tree perfectly balanced, so instead we keep trees
-// approximately balanced.  A tree node N of depth D(N) that contains a string
-// of L(N) characters is considered balanced if L >= Fibonacci(D + 2).
-// The "+ 2" is used to ensure that every balanced leaf node contains at least
-//  one character. Here we presume that
-//   Fibonacci(0) = 0
-//   Fibonacci(1) = 1
-//   Fibonacci(2) = 1
-//   Fibonacci(3) = 2
-//   ...
-// The algorithm is based on paper by Hans Boehm et al:
-// https://www.cs.rit.edu/usr/local/pub/jeh/courses/QUARTERS/FP/Labs/CedarRope/rope-paper.pdf
-// In this paper authors shows that rebalancing based on cord forest of already
-// balanced subtrees can be proven to never produce tree of depth larger than
-// largest Fibonacci number representable in the same integral type as cord size
-// For 64 bit integers this is the 93rd Fibonacci number. For 32 bit integrals
-// this is 47th Fibonacci number.
-constexpr size_t MaxCordDepth() { return sizeof(size_t) == 8 ? 93 : 47; }
-
-// This class models fixed max size stack of CordRep pointers.
-// The elements are being pushed back and popped from the back.
-template <typename CordRepPtr, size_t N>
-class CordTreePath {
- public:
-  CordTreePath() {}
-  explicit CordTreePath(CordRepPtr root) { push_back(root); }
-
-  bool empty() const { return size_ == 0; }
-  size_t size() const { return size_; }
-  void clear() { size_ = 0; }
-
-  CordRepPtr back() { return data_[size_ - 1]; }
-
-  void pop_back() {
-    --size_;
-    assert(size_ < N);
-  }
-  void push_back(CordRepPtr elem) { data_[size_++] = elem; }
-
- private:
-  CordRepPtr data_[N];
-  size_t size_ = 0;
-};
-
-using CordTreeMutablePath = CordTreePath<CordRep*, MaxCordDepth()>;
-}  // namespace cord_internal
-
 // A Cord is a sequence of characters.
 class Cord {
  private:
@@ -333,7 +285,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;
-    absl::cord_internal::CordTreeMutablePath stack_of_right_children_;
+    absl::InlinedVector<absl::cord_internal::CordRep*, 4>
+        stack_of_right_children_;
   };
 
   // Returns an iterator to the first chunk of the `Cord`.