diff options
author | Abseil Team <absl-team@google.com> | 2020-09-25 10:29:25 -0700 |
---|---|---|
committer | Andy Getz <durandal@google.com> | 2020-09-28 23:47:58 -0400 |
commit | d1de75bf540f091b4dfc860713d556e578c0f158 (patch) | |
tree | 91669db9a8381dd2c89c548e8e5a008064bee2b3 /absl/strings/internal/cord_internal.h | |
parent | cad3f30b44c2bfac54ee82c6fc9e49ba49078620 (diff) |
Export of internal Abseil changes
--
f50d25c8f8491ef7031cbbcad78edd15f98c2bd1 by Abseil Team <absl-team@google.com>:
Add myriad2 to HAVE_MMAP
Remove mutex_nonprod and associated defines.
PiperOrigin-RevId: 333759830
--
25ef4c577ea983aa3fcd6cfe2af6cdc62a06f520 by Samuel Benzaquen <sbenza@google.com>:
Internal refactor.
Represent the data with a union to allow for better constexpr support in the future.
PiperOrigin-RevId: 333756733
GitOrigin-RevId: f50d25c8f8491ef7031cbbcad78edd15f98c2bd1
Change-Id: Ieecd2c47cb20de638726eb3f9fc2e5682d05dcca
Diffstat (limited to 'absl/strings/internal/cord_internal.h')
-rw-r--r-- | absl/strings/internal/cord_internal.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/absl/strings/internal/cord_internal.h b/absl/strings/internal/cord_internal.h index d456eef8..00b9baa9 100644 --- a/absl/strings/internal/cord_internal.h +++ b/absl/strings/internal/cord_internal.h @@ -85,6 +85,17 @@ struct CordRepConcat; struct CordRepSubstring; struct CordRepExternal; +// Various representations that we allow +enum CordRepKind { + CONCAT = 0, + EXTERNAL = 1, + SUBSTRING = 2, + + // We have different tags for different sized flat arrays, + // starting with FLAT + FLAT = 3, +}; + struct CordRep { // The following three fields have to be less than 32 bytes since // that is the smallest supported flat node size. @@ -167,6 +178,34 @@ struct CordRepExternalImpl } }; +enum { + kMaxInline = 15, + // Tag byte & kMaxInline means we are storing a pointer. + kTreeFlag = 1 << 4, + // Tag byte & kProfiledFlag means we are profiling the Cord. + kProfiledFlag = 1 << 5 +}; + +// If the data has length <= kMaxInline, we store it in `as_chars`, and +// store the size in `tagged_size`. +// Else we store it in a tree and store a pointer to that tree in +// `as_tree.rep` and store a tag in `tagged_size`. +struct AsTree { + absl::cord_internal::CordRep* rep; + char padding[kMaxInline + 1 - sizeof(absl::cord_internal::CordRep*) - 1]; + char tagged_size; +}; +union InlineData { + constexpr InlineData() : as_chars{} {} + explicit constexpr InlineData(AsTree tree) : as_tree(tree) {} + + AsTree as_tree; + char as_chars[kMaxInline + 1]; +}; +static_assert(sizeof(InlineData) == kMaxInline + 1, ""); +static_assert(sizeof(AsTree) == sizeof(InlineData), ""); +static_assert(offsetof(AsTree, tagged_size) == kMaxInline, ""); + } // namespace cord_internal ABSL_NAMESPACE_END } // namespace absl |