diff options
author | Abseil Team <absl-team@google.com> | 2020-11-23 17:05:17 -0800 |
---|---|---|
committer | Gennadiy Rozental <rogeeff@google.com> | 2020-11-24 02:43:25 -0500 |
commit | 5d8fc9192245f0ea67094af57399d7931d6bd53f (patch) | |
tree | 99d50d3b52bbd768ee5f5c1d7ecf8c46678e7192 /absl/strings | |
parent | e19260fd7dbef881492fd73891e0be5bd4a09b95 (diff) |
Export of internal Abseil changes
--
fcedaa5714efab8738446fa21620b827a40a3458 by Derek Mauro <dmauro@google.com>:
Uses Wyhash in the implementation of absl::Hash for hashing sequences
of more than 16 bytes on some platforms.
Due to the per-process randomization of the seed used by absl::Hash, users
should not notice this change, other than possibly getting better performance.
This change only affects platforms where absl::uint128 is implemented
with an intrinsic (and where sizeof(size_t)==8) since Wyhash relies on
fast 128-bit multiplication for speed.
PiperOrigin-RevId: 343956735
--
085e108c760084f19caa21dbeb2118de2be3f8f0 by Abseil Team <absl-team@google.com>:
Internal change for cord ring
PiperOrigin-RevId: 343919274
--
4c333278ad14d6692f203074b902506008ad624a by Jorg Brown <jorg@google.com>:
Minimize strings_internal::StringConstant further, by removing the need for the compiler to instantiate a compile-time class function.
PiperOrigin-RevId: 343878568
--
71c3c8c7b7821b67997e3d5345aaec67f93f266f by Abseil Team <absl-team@google.com>:
Internal change
PiperOrigin-RevId: 343838259
GitOrigin-RevId: fcedaa5714efab8738446fa21620b827a40a3458
Change-Id: Ifb91895a82d11e743acd42fe97ab7fb70712b7df
Diffstat (limited to 'absl/strings')
-rw-r--r-- | absl/strings/cord.cc | 17 | ||||
-rw-r--r-- | absl/strings/internal/cord_internal.h | 10 | ||||
-rw-r--r-- | absl/strings/internal/string_constant.h | 12 |
3 files changed, 26 insertions, 13 deletions
diff --git a/absl/strings/cord.cc b/absl/strings/cord.cc index 9efd1357..ec1e9709 100644 --- a/absl/strings/cord.cc +++ b/absl/strings/cord.cc @@ -53,6 +53,7 @@ using ::absl::cord_internal::CordRepSubstring; using ::absl::cord_internal::CONCAT; using ::absl::cord_internal::EXTERNAL; using ::absl::cord_internal::FLAT; +using ::absl::cord_internal::MAX_FLAT_TAG; using ::absl::cord_internal::SUBSTRING; namespace cord_internal { @@ -95,9 +96,21 @@ static const size_t kFlatOverhead = offsetof(CordRep, data); // Flat allocation size is stored in tag, which currently can encode sizes up // to 4K, encoded as multiple of either 8 or 32 bytes. // If we allow for larger sizes, we need to change this to 8/64, 16/128, etc. +// kMinFlatSize is bounded by tag needing to be at least FLAT * 8 bytes, and +// ideally a 'nice' size aligning with allocation and cacheline sizes like 32. +// kMaxFlatSize is bounded by the size resulting in a computed tag no greater +// than MAX_FLAT_TAG. MAX_FLAT_TAG provides for additional 'high' tag values. +static constexpr size_t kMinFlatSize = 32; static constexpr size_t kMaxFlatSize = 4096; static constexpr size_t kMaxFlatLength = kMaxFlatSize - kFlatOverhead; -static constexpr size_t kMinFlatLength = 32 - kFlatOverhead; +static constexpr size_t kMinFlatLength = kMinFlatSize - kFlatOverhead; + +static constexpr size_t AllocatedSizeToTagUnchecked(size_t size) { + return (size <= 1024) ? size / 8 : 128 + size / 32 - 1024 / 32; +} + +static_assert(kMinFlatSize / 8 >= FLAT, ""); +static_assert(AllocatedSizeToTagUnchecked(kMaxFlatSize) <= MAX_FLAT_TAG, ""); // Prefer copying blocks of at most this size, otherwise reference count. static const size_t kMaxBytesToCopy = 511; @@ -117,7 +130,7 @@ static size_t RoundUpForTag(size_t size) { // undefined if the size exceeds the maximum size that can be encoded in // a tag, i.e., if size is larger than TagToAllocatedSize(<max tag>). static uint8_t AllocatedSizeToTag(size_t size) { - const size_t tag = (size <= 1024) ? size / 8 : 128 + size / 32 - 1024 / 32; + const size_t tag = AllocatedSizeToTagUnchecked(size); assert(tag <= std::numeric_limits<uint8_t>::max()); return tag; } diff --git a/absl/strings/internal/cord_internal.h b/absl/strings/internal/cord_internal.h index aa91a691..195a7988 100644 --- a/absl/strings/internal/cord_internal.h +++ b/absl/strings/internal/cord_internal.h @@ -116,10 +116,16 @@ enum CordRepKind { CONCAT = 0, EXTERNAL = 1, SUBSTRING = 2, + RING = 3, // We have different tags for different sized flat arrays, - // starting with FLAT - FLAT = 3, + // starting with FLAT, and limited to MAX_FLAT_TAG. The 224 value is based on + // the current 'size to tag' encoding of 8 / 32 bytes. If a new tag is needed + // in the future, then 'FLAT' and 'MAX_FLAT_TAG' should be adjusted as well + // as the Tag <---> Size logic so that FLAT stil represents the minimum flat + // allocation size. (32 bytes as of now). + FLAT = 4, + MAX_FLAT_TAG = 224, }; struct CordRep { diff --git a/absl/strings/internal/string_constant.h b/absl/strings/internal/string_constant.h index b15f1d9b..a11336b7 100644 --- a/absl/strings/internal/string_constant.h +++ b/absl/strings/internal/string_constant.h @@ -35,18 +35,12 @@ namespace strings_internal { // below. template <typename T> struct StringConstant { - private: - // Returns true if `view` points to constant data. - // Otherwise, it can't be constant evaluated. - static constexpr bool ValidateConstant(absl::string_view view) { - return view.empty() || 2 * view[0] != 1; - } - - public: static constexpr absl::string_view value = T{}(); constexpr absl::string_view operator()() const { return value; } - static_assert(ValidateConstant(value), + // Check to be sure `view` points to constant data. + // Otherwise, it can't be constant evaluated. + static_assert(value.empty() || 2 * value[0] != 1, "The input string_view must point to constant data."); }; |