summaryrefslogtreecommitdiff
path: root/absl/strings/cord.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2020-11-23 17:05:17 -0800
committerGravatar Gennadiy Rozental <rogeeff@google.com>2020-11-24 02:43:25 -0500
commit5d8fc9192245f0ea67094af57399d7931d6bd53f (patch)
tree99d50d3b52bbd768ee5f5c1d7ecf8c46678e7192 /absl/strings/cord.cc
parente19260fd7dbef881492fd73891e0be5bd4a09b95 (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/cord.cc')
-rw-r--r--absl/strings/cord.cc17
1 files changed, 15 insertions, 2 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;
}