|
|
|
// Copyright 2020 The Abseil Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// File: cord.h
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// This file defines the `absl::Cord` data structure and operations on that data
|
|
|
|
// structure. A Cord is a string-like sequence of characters optimized for
|
|
|
|
// specific use cases. Unlike a `std::string`, which stores an array of
|
|
|
|
// contiguous characters, Cord data is stored in a structure consisting of
|
|
|
|
// separate, reference-counted "chunks." (Currently, this implementation is a
|
|
|
|
// tree structure, though that implementation may change.)
|
|
|
|
//
|
|
|
|
// Because a Cord consists of these chunks, data can be added to or removed from
|
|
|
|
// a Cord during its lifetime. Chunks may also be shared between Cords. Unlike a
|
|
|
|
// `std::string`, a Cord can therefore accommodate data that changes over its
|
|
|
|
// lifetime, though it's not quite "mutable"; it can change only in the
|
|
|
|
// attachment, detachment, or rearrangement of chunks of its constituent data.
|
|
|
|
//
|
|
|
|
// A Cord provides some benefit over `std::string` under the following (albeit
|
|
|
|
// narrow) circumstances:
|
|
|
|
//
|
|
|
|
// * Cord data is designed to grow and shrink over a Cord's lifetime. Cord
|
|
|
|
// provides efficient insertions and deletions at the start and end of the
|
|
|
|
// character sequences, avoiding copies in those cases. Static data should
|
|
|
|
// generally be stored as strings.
|
|
|
|
// * External memory consisting of string-like data can be directly added to
|
|
|
|
// a Cord without requiring copies or allocations.
|
|
|
|
// * Cord data may be shared and copied cheaply. Cord provides a copy-on-write
|
|
|
|
// implementation and cheap sub-Cord operations. Copying a Cord is an O(1)
|
|
|
|
// operation.
|
|
|
|
//
|
|
|
|
// As a consequence to the above, Cord data is generally large. Small data
|
|
|
|
// should generally use strings, as construction of a Cord requires some
|
|
|
|
// overhead. Small Cords (<= 15 bytes) are represented inline, but most small
|
|
|
|
// Cords are expected to grow over their lifetimes.
|
|
|
|
//
|
|
|
|
// Note that because a Cord is made up of separate chunked data, random access
|
|
|
|
// to character data within a Cord is slower than within a `std::string`.
|
|
|
|
//
|
|
|
|
// Thread Safety
|
|
|
|
//
|
|
|
|
// Cord has the same thread-safety properties as many other types like
|
|
|
|
// std::string, std::vector<>, int, etc -- it is thread-compatible. In
|
|
|
|
// particular, if threads do not call non-const methods, then it is safe to call
|
|
|
|
// const methods without synchronization. Copying a Cord produces a new instance
|
|
|
|
// that can be used concurrently with the original in arbitrary ways.
|
|
|
|
|
|
|
|
#ifndef ABSL_STRINGS_CORD_H_
|
|
|
|
#define ABSL_STRINGS_CORD_H_
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstring>
|
|
|
|
#include <iosfwd>
|
|
|
|
#include <iterator>
|
|
|
|
#include <string>
|
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
#include "absl/base/attributes.h"
|
|
|
|
#include "absl/base/config.h"
|
|
|
|
#include "absl/base/internal/endian.h"
|
|
|
|
#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/cord_analysis.h"
|
|
|
|
#include "absl/strings/internal/cord_internal.h"
|
|
|
|
#include "absl/strings/internal/cord_rep_btree.h"
|
|
|
|
#include "absl/strings/internal/cord_rep_btree_reader.h"
|
Export of internal Abseil changes
--
83e4cdf03a4d702b30e69204060de09e462e23c6 by Greg Falcon <gfalcon@google.com>:
Revert the crc addition to RefcountAndFlags, and restore related comments to their original state.
In development, the implementation of SetExpectedCrc() changed, and there is no longer a need to track the CRC status in the refcount.
Since the distinction between IsOne() and IsMutable() is subtle *and unused*, removing it now can help avoid subtle bugs in the future. This distinction can always be added back later, if it proves necessary.
Keep the reserved bit for now; all it costs is one extra mask instruction in the refcount checks, and space for extra state in Cord is always hard to find.
PiperOrigin-RevId: 408647038
--
ee67585cf66954176615271f50f8b278119dd138 by Greg Falcon <gfalcon@google.com>:
Implement Cord::SetExpectedChecksum() and Cord::ExpectedChecksum().
SetExpectedChecksum() will store a uint32_t out-of-band alongside a Cord's data. This value persists through copies and assignments. Mutating operations on a Cord cause the value to be forgotten. ExpectedChecksum() retrieves the stored value, if present.
This API is intended for storing a CRC32C checksum alongside data, allowing checksums to be passed through dataflows and validated at the final step. However, this API is agnostic to the meaning of the stored value. No CRC32C validation is performed by these new APIs.
This implementation adds a new CordRep node, CordRepCrc. A CordRepCrc may (currently) only live at the top of a tree. This allows traversal logic to be agnostic to these nodes, instead putting the needed branches at the mutation level. This also implements the property requested from API review, that any mutation is guaranteed to permanently forget the stored CRC.
PiperOrigin-RevId: 408611221
--
a86f592402b37c854ebdc77d2b9b425451a7a675 by Martijn Vels <mvels@google.com>:
Move 'ExtractResult' into CordRep
The result of an extract operation is logically identical for any tree implementation, and having a single type makes 'tree independent' implementation in cord.cc more concise.
PiperOrigin-RevId: 408332408
--
baa7647e21db59a87f75af9cac62172ce38a0f71 by Abseil Team <absl-team@google.com>:
Replace usages of `assert` macros with `ABSL_HARDENING_ASSERT`.
PiperOrigin-RevId: 408272133
--
c7658133d8662c39fa5035fc93a364c7c3d327e0 by Martijn Vels <mvels@google.com>:
Add CordRepBtree::ExtractAppendBuffer
PiperOrigin-RevId: 407944179
--
5775100363b5890ebfe710fadebf040445eab991 by Martijn Vels <mvels@google.com>:
Add CordRepConcat::ExtractAppendBuffer
PiperOrigin-RevId: 407932968
--
9f520ba1600a93352c78f644a369c7c76195ee86 by Greg Falcon <gfalcon@google.com>:
Add cordz tracking for crc nodes.
This also adds a new kSetExpectedChecksum method to the list of tracked methods. This is presently unused but will be used soon.
PiperOrigin-RevId: 407884120
GitOrigin-RevId: 83e4cdf03a4d702b30e69204060de09e462e23c6
Change-Id: I134ace2d87215813eaa60a282996a33884676c06
3 years ago
|
|
|
#include "absl/strings/internal/cord_rep_crc.h"
|
|
|
|
#include "absl/strings/internal/cord_rep_ring.h"
|
|
|
|
#include "absl/strings/internal/cordz_functions.h"
|
|
|
|
#include "absl/strings/internal/cordz_info.h"
|
|
|
|
#include "absl/strings/internal/cordz_statistics.h"
|
|
|
|
#include "absl/strings/internal/cordz_update_scope.h"
|
Export of internal Abseil changes
--
ac1df60490c9583e475e22de7adfc40023196fbf by Martijn Vels <mvels@google.com>:
Change Cord constructor(string_view) to explicit make_tree and Cordz tracking
This CL changes the ctor to use an easier to maintain model where Cord code explicitly invokes Cordz update or new / tree logic, which avoids the ambiguity of the 'branched' InlineRep::set_tree code. This removes the need to equip InlineRep with 'MethodIdentifier' or other necessary call info, and also is a cleaner model: InlineRep is carrying too much code now that should plainly sit in Cord, especially with all internal abstractions having moved to InlineData.
See child CL(s) for desired state
PiperOrigin-RevId: 369433619
--
b665af7f586e6c679a8b27d4f78d5a1d2b596058 by Abseil Team <absl-team@google.com>:
Rename the 'Compare' template type to 'LessThan', as the passed-in function is expected to act like operator<. It is worth avoiding confusion with std::compare, which returns an int (-1/0/1), as due to implicit casting this can lead to hard-to-spot bugs.
PiperOrigin-RevId: 369391118
--
c3c775269cad0f4982ec63f3616dd78bb9e52dca by Martijn Vels <mvels@google.com>:
Integrate CordzUpdateTracker into CordzInfo
PiperOrigin-RevId: 369348824
--
771d81ed357496c117179e1daec76eba5155932d by Martijn Vels <mvels@google.com>:
Replace mutex() with Lock() / Unlock() function
Mini design future tracking of CordzInfo sampled cords: CordzInfo holds a CordRep* reference without a reference count. Cord is responsible for synchronizing updates for sampled cords such that the CordRep* contained in CordzInfo is at all times valid. This is done by scoping Lock() and Unlock() calls around the code modifying the code of a sampled cord. For example (using the future CL CordzUpdateScope()):
CordzInfo* cordz_info = get_cordz_info();
CordzUpdateScope scope(cordz_info, CordzUpdateTracker::kRemovePrefix);
CordRep* rep = RemovePrefixImpl(root);
set_tree(rep);
if (cordz_info) {
cordz_info->SetCordRep(rep);
}
On CordzInfo::Unlock(), if the internal rep is null, the cord is no longer sampled, and CordzInfo will be deleted. Thus any update resulting in the Cord being inlined will automatically no longer be sampled.
PiperOrigin-RevId: 369338802
--
5563c12df04a1e965a03b50bdd032739c55c0706 by Martijn Vels <mvels@google.com>:
Add UpdateTracker to CordzStatistics
PiperOrigin-RevId: 369318178
--
6b4d8463722a3e55a3e8f6cb3741a41055e7f83e by Martijn Vels <mvels@google.com>:
Add kClear, kConstructor* and kUnknown values and fix typo
PiperOrigin-RevId: 369297163
--
041adcbc929789d6d53371a8236840fc350e1eeb by Derek Mauro <dmauro@google.com>:
Switch from malloc to operator new in pool_urbg.cc
so it can only fail by throwing/aborting
PiperOrigin-RevId: 369274087
--
5d97a5f43e3f2d02d0a5bbe586d93b5751812981 by Benjamin Barenblat <bbaren@google.com>:
Correct Thumb function bound computation in the symbolizer
On 32-bit ARM, all functions are aligned to multiples of two bytes, and
the lowest-order bit in a function’s address is ignored by the CPU when
computing branch targets. That bit is still present in instructions and
ELF symbol tables, though; it’s repurposed to indicate whether the
function contains ARM or Thumb code. If the symbolizer doesn’t ignore
that bit, it will believe Thumb functions have boundaries that are off
by one byte, so instruct the symbolizer to null out the lowest-order bit
after retrieving it from the symbol table.
PiperOrigin-RevId: 369254082
--
462bb307c6cc332c1e2c3adb5f0cad51804bf937 by Derek Mauro <dmauro@google.com>:
Add a check for malloc failure in pool_urbg.cc
GitHub #940
PiperOrigin-RevId: 369238100
GitOrigin-RevId: ac1df60490c9583e475e22de7adfc40023196fbf
Change-Id: Ic6ec91c62cd3a0031f6a75a43a83da959ece2d25
4 years ago
|
|
|
#include "absl/strings/internal/cordz_update_tracker.h"
|
|
|
|
#include "absl/strings/internal/resize_uninitialized.h"
|
|
|
|
#include "absl/strings/internal/string_constant.h"
|
|
|
|
#include "absl/strings/string_view.h"
|
|
|
|
#include "absl/types/optional.h"
|
|
|
|
|
|
|
|
namespace absl {
|
|
|
|
ABSL_NAMESPACE_BEGIN
|
|
|
|
class Cord;
|
|
|
|
class CordTestPeer;
|
|
|
|
template <typename Releaser>
|
|
|
|
Cord MakeCordFromExternal(absl::string_view, Releaser&&);
|
|
|
|
void CopyCordToString(const Cord& src, std::string* dst);
|
|
|
|
|
|
|
|
// Cord memory accounting modes
|
|
|
|
enum class CordMemoryAccounting {
|
|
|
|
// Counts the *approximate* number of bytes held in full or in part by this
|
|
|
|
// Cord (which may not remain the same between invocations). Cords that share
|
|
|
|
// memory could each be "charged" independently for the same shared memory.
|
|
|
|
kTotal,
|
|
|
|
|
|
|
|
// Counts the *approximate* number of bytes held in full or in part by this
|
|
|
|
// Cord weighted by the sharing ratio of that data. For example, if some data
|
|
|
|
// edge is shared by 4 different Cords, then each cord is attributed 1/4th of
|
|
|
|
// the total memory usage as a 'fair share' of the total memory usage.
|
|
|
|
kFairShare,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Cord
|
|
|
|
//
|
|
|
|
// A Cord is a sequence of characters, designed to be more efficient than a
|
|
|
|
// `std::string` in certain circumstances: namely, large string data that needs
|
|
|
|
// to change over its lifetime or shared, especially when such data is shared
|
|
|
|
// across API boundaries.
|
|
|
|
//
|
|
|
|
// A Cord stores its character data in a structure that allows efficient prepend
|
|
|
|
// and append operations. This makes a Cord useful for large string data sent
|
|
|
|
// over in a wire format that may need to be prepended or appended at some point
|
|
|
|
// during the data exchange (e.g. HTTP, protocol buffers). For example, a
|
|
|
|
// Cord is useful for storing an HTTP request, and prepending an HTTP header to
|
|
|
|
// such a request.
|
|
|
|
//
|
|
|
|
// Cords should not be used for storing general string data, however. They
|
|
|
|
// require overhead to construct and are slower than strings for random access.
|
|
|
|
//
|
|
|
|
// The Cord API provides the following common API operations:
|
|
|
|
//
|
|
|
|
// * Create or assign Cords out of existing string data, memory, or other Cords
|
|
|
|
// * Append and prepend data to an existing Cord
|
|
|
|
// * Create new Sub-Cords from existing Cord data
|
|
|
|
// * Swap Cord data and compare Cord equality
|
|
|
|
// * Write out Cord data by constructing a `std::string`
|
|
|
|
//
|
|
|
|
// Additionally, the API provides iterator utilities to iterate through Cord
|
|
|
|
// data via chunks or character bytes.
|
|
|
|
//
|
|
|
|
class Cord {
|
|
|
|
private:
|
|
|
|
template <typename T>
|
|
|
|
using EnableIfString =
|
|
|
|
absl::enable_if_t<std::is_same<T, std::string>::value, int>;
|
|
|
|
|
|
|
|
public:
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// Cord::Cord() Constructors.
|
|
|
|
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// Creates an empty Cord.
|
|
|
|
constexpr Cord() noexcept;
|
|
|
|
|
|
|
|
// Creates a Cord from an existing Cord. Cord is copyable and efficiently
|
|
|
|
// movable. The moved-from state is valid but unspecified.
|
|
|
|
Cord(const Cord& src);
|
|
|
|
Cord(Cord&& src) noexcept;
|
|
|
|
Cord& operator=(const Cord& x);
|
|
|
|
Cord& operator=(Cord&& x) noexcept;
|
|
|
|
|
|
|
|
// Creates a Cord from a `src` string. This constructor is marked explicit to
|
|
|
|
// prevent implicit Cord constructions from arguments convertible to an
|
|
|
|
// `absl::string_view`.
|
|
|
|
explicit Cord(absl::string_view src);
|
|
|
|
Cord& operator=(absl::string_view src);
|
|
|
|
|
|
|
|
// Creates a Cord from a `std::string&&` rvalue. These constructors are
|
|
|
|
// templated to avoid ambiguities for types that are convertible to both
|
|
|
|
// `absl::string_view` and `std::string`, such as `const char*`.
|
|
|
|
template <typename T, EnableIfString<T> = 0>
|
Export of internal Abseil changes
--
7d0468a6610ed85586d5c87fd65de8dac5118923 by Derek Mauro <dmauro@google.com>:
Import of CCTZ from GitHub.
PiperOrigin-RevId: 313226473
--
1131ef6d116f5ce7d46537a82f300ea06dcaaa53 by Gennadiy Rozental <rogeeff@google.com>:
Migrate internal interface to use mutable references.
PiperOrigin-RevId: 312931131
--
96225212a9f5fbd0b38c71fe65539164992c7c3b by Laramie Leavitt <lar@google.com>:
Remove random/internal/distributions.h
This file was something of an historical artifact. All of the related
code has either been removed or migraged, and so the only remaining type
belongs with uniform_helper.h, as it is used to infer the return type
of the absl::Uniform method in a few cases.
PiperOrigin-RevId: 312878173
--
6dcbd5be58ad425e08740ff64088373ee7fe4a72 by Mark Barolak <mbar@google.com>:
Release the StrFormat test case for Cords to open source.
PiperOrigin-RevId: 312707974
--
34484d18dfb63a0a7ad6e2aaeb570e33592968be by Abseil Team <absl-team@google.com>:
Let Cord::Cord(string&&), Cord::operator=(string&&),
Cord::Append(string&&), and Cord::Prepend(string&&) steal string data
and embed it into the Cord as a single external chunk, instead of
copying it into flat chunks (at most 4083-byte each).
Stealing string data is faster, but it creates a long chunk, which leads
to a higher more memory usage if its subcords are created and outlive
the whole Cord.
These functions revert to copying the data if any of the following
conditions holds:
- string size is at most kMaxBytesToCopy (511), to avoid the overhead
of an external chunk for short strings;
- less than half of string capacity is used, to avoid pinning to much
unused memory.
PiperOrigin-RevId: 312683785
GitOrigin-RevId: 7d0468a6610ed85586d5c87fd65de8dac5118923
Change-Id: If79b5a1dfe6d53a8ddddbc7da84338f11fc4cfa3
5 years ago
|
|
|
explicit Cord(T&& src);
|
|
|
|
template <typename T, EnableIfString<T> = 0>
|
|
|
|
Cord& operator=(T&& src);
|
|
|
|
|
|
|
|
// Cord::~Cord()
|
|
|
|
//
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// Destructs the Cord.
|
|
|
|
~Cord() {
|
|
|
|
if (contents_.is_tree()) DestroyCordSlow();
|
|
|
|
}
|
|
|
|
|
|
|
|
// MakeCordFromExternal()
|
|
|
|
//
|
|
|
|
// Creates a Cord that takes ownership of external string memory. The
|
|
|
|
// contents of `data` are not copied to the Cord; instead, the external
|
|
|
|
// memory is added to the Cord and reference-counted. This data may not be
|
|
|
|
// changed for the life of the Cord, though it may be prepended or appended
|
|
|
|
// to.
|
|
|
|
//
|
|
|
|
// `MakeCordFromExternal()` takes a callable "releaser" that is invoked when
|
|
|
|
// the reference count for `data` reaches zero. As noted above, this data must
|
|
|
|
// remain live until the releaser is invoked. The callable releaser also must:
|
|
|
|
//
|
|
|
|
// * be move constructible
|
|
|
|
// * support `void operator()(absl::string_view) const` or `void operator()`
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// Cord MakeCord(BlockPool* pool) {
|
|
|
|
// Block* block = pool->NewBlock();
|
|
|
|
// FillBlock(block);
|
|
|
|
// return absl::MakeCordFromExternal(
|
|
|
|
// block->ToStringView(),
|
|
|
|
// [pool, block](absl::string_view v) {
|
|
|
|
// pool->FreeBlock(block, v);
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// WARNING: Because a Cord can be reference-counted, it's likely a bug if your
|
|
|
|
// releaser doesn't do anything. For example, consider the following:
|
|
|
|
//
|
|
|
|
// void Foo(const char* buffer, int len) {
|
|
|
|
// auto c = absl::MakeCordFromExternal(absl::string_view(buffer, len),
|
|
|
|
// [](absl::string_view) {});
|
|
|
|
//
|
|
|
|
// // BUG: If Bar() copies its cord for any reason, including keeping a
|
|
|
|
// // substring of it, the lifetime of buffer might be extended beyond
|
|
|
|
// // when Foo() returns.
|
|
|
|
// Bar(c);
|
|
|
|
// }
|
|
|
|
template <typename Releaser>
|
|
|
|
friend Cord MakeCordFromExternal(absl::string_view data, Releaser&& releaser);
|
|
|
|
|
|
|
|
// Cord::Clear()
|
|
|
|
//
|
|
|
|
// Releases the Cord data. Any nodes that share data with other Cords, if
|
|
|
|
// applicable, will have their reference counts reduced by 1.
|
|
|
|
ABSL_ATTRIBUTE_REINITIALIZES void Clear();
|
|
|
|
|
|
|
|
// Cord::Append()
|
|
|
|
//
|
|
|
|
// Appends data to the Cord, which may come from another Cord or other string
|
|
|
|
// data.
|
|
|
|
void Append(const Cord& src);
|
|
|
|
void Append(Cord&& src);
|
|
|
|
void Append(absl::string_view src);
|
|
|
|
template <typename T, EnableIfString<T> = 0>
|
|
|
|
void Append(T&& src);
|
|
|
|
|
|
|
|
// Cord::Prepend()
|
|
|
|
//
|
|
|
|
// Prepends data to the Cord, which may come from another Cord or other string
|
|
|
|
// data.
|
|
|
|
void Prepend(const Cord& src);
|
|
|
|
void Prepend(absl::string_view src);
|
|
|
|
template <typename T, EnableIfString<T> = 0>
|
|
|
|
void Prepend(T&& src);
|
|
|
|
|
|
|
|
// Cord::RemovePrefix()
|
|
|
|
//
|
|
|
|
// Removes the first `n` bytes of a Cord.
|
|
|
|
void RemovePrefix(size_t n);
|
|
|
|
void RemoveSuffix(size_t n);
|
|
|
|
|
|
|
|
// Cord::Subcord()
|
|
|
|
//
|
|
|
|
// Returns a new Cord representing the subrange [pos, pos + new_size) of
|
|
|
|
// *this. If pos >= size(), the result is empty(). If
|
|
|
|
// (pos + new_size) >= size(), the result is the subrange [pos, size()).
|
|
|
|
Cord Subcord(size_t pos, size_t new_size) const;
|
|
|
|
|
|
|
|
// Cord::swap()
|
|
|
|
//
|
|
|
|
// Swaps the contents of the Cord with `other`.
|
|
|
|
void swap(Cord& other) noexcept;
|
|
|
|
|
|
|
|
// swap()
|
|
|
|
//
|
|
|
|
// Swaps the contents of two Cords.
|
|
|
|
friend void swap(Cord& x, Cord& y) noexcept { x.swap(y); }
|
|
|
|
|
|
|
|
// Cord::size()
|
|
|
|
//
|
|
|
|
// Returns the size of the Cord.
|
|
|
|
size_t size() const;
|
|
|
|
|
|
|
|
// Cord::empty()
|
|
|
|
//
|
|
|
|
// Determines whether the given Cord is empty, returning `true` is so.
|
|
|
|
bool empty() const;
|
|
|
|
|
|
|
|
// Cord::EstimatedMemoryUsage()
|
|
|
|
//
|
|
|
|
// Returns the *approximate* number of bytes held by this cord.
|
|
|
|
// See CordMemoryAccounting for more information on accounting method used.
|
|
|
|
size_t EstimatedMemoryUsage(CordMemoryAccounting accounting_method =
|
|
|
|
CordMemoryAccounting::kTotal) const;
|
|
|
|
|
|
|
|
// Cord::Compare()
|
|
|
|
//
|
|
|
|
// Compares 'this' Cord with rhs. This function and its relatives treat Cords
|
|
|
|
// as sequences of unsigned bytes. The comparison is a straightforward
|
|
|
|
// lexicographic comparison. `Cord::Compare()` returns values as follows:
|
|
|
|
//
|
|
|
|
// -1 'this' Cord is smaller
|
|
|
|
// 0 two Cords are equal
|
|
|
|
// 1 'this' Cord is larger
|
|
|
|
int Compare(absl::string_view rhs) const;
|
|
|
|
int Compare(const Cord& rhs) const;
|
|
|
|
|
|
|
|
// Cord::StartsWith()
|
|
|
|
//
|
|
|
|
// Determines whether the Cord starts with the passed string data `rhs`.
|
|
|
|
bool StartsWith(const Cord& rhs) const;
|
|
|
|
bool StartsWith(absl::string_view rhs) const;
|
|
|
|
|
|
|
|
// Cord::EndsWith()
|
|
|
|
//
|
|
|
|
// Determines whether the Cord ends with the passed string data `rhs`.
|
|
|
|
bool EndsWith(absl::string_view rhs) const;
|
|
|
|
bool EndsWith(const Cord& rhs) const;
|
|
|
|
|
|
|
|
// Cord::operator std::string()
|
|
|
|
//
|
|
|
|
// Converts a Cord into a `std::string()`. This operator is marked explicit to
|
|
|
|
// prevent unintended Cord usage in functions that take a string.
|
|
|
|
explicit operator std::string() const;
|
|
|
|
|
|
|
|
// CopyCordToString()
|
|
|
|
//
|
|
|
|
// Copies the contents of a `src` Cord into a `*dst` string.
|
|
|
|
//
|
|
|
|
// This function optimizes the case of reusing the destination string since it
|
|
|
|
// can reuse previously allocated capacity. However, this function does not
|
|
|
|
// guarantee that pointers previously returned by `dst->data()` remain valid
|
|
|
|
// even if `*dst` had enough capacity to hold `src`. If `*dst` is a new
|
|
|
|
// object, prefer to simply use the conversion operator to `std::string`.
|
|
|
|
friend void CopyCordToString(const Cord& src, std::string* dst);
|
|
|
|
|
|
|
|
class CharIterator;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Cord::ChunkIterator
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// A `Cord::ChunkIterator` allows iteration over the constituent chunks of its
|
|
|
|
// Cord. Such iteration allows you to perform non-const operatons on the data
|
|
|
|
// of a Cord without modifying it.
|
|
|
|
//
|
|
|
|
// Generally, you do not instantiate a `Cord::ChunkIterator` directly;
|
|
|
|
// instead, you create one implicitly through use of the `Cord::Chunks()`
|
|
|
|
// member function.
|
|
|
|
//
|
|
|
|
// The `Cord::ChunkIterator` has the following properties:
|
|
|
|
//
|
|
|
|
// * The iterator is invalidated after any non-const operation on the
|
|
|
|
// Cord object over which it iterates.
|
|
|
|
// * The `string_view` returned by dereferencing a valid, non-`end()`
|
|
|
|
// iterator is guaranteed to be non-empty.
|
|
|
|
// * Two `ChunkIterator` objects can be compared equal if and only if they
|
|
|
|
// remain valid and iterate over the same Cord.
|
|
|
|
// * The iterator in this case is a proxy iterator; the `string_view`
|
|
|
|
// returned by the iterator does not live inside the Cord, and its
|
|
|
|
// lifetime is limited to the lifetime of the iterator itself. To help
|
|
|
|
// prevent lifetime issues, `ChunkIterator::reference` is not a true
|
|
|
|
// reference type and is equivalent to `value_type`.
|
|
|
|
// * The iterator keeps state that can grow for Cords that contain many
|
|
|
|
// nodes and are imbalanced due to sharing. Prefer to pass this type by
|
|
|
|
// const reference instead of by value.
|
|
|
|
class ChunkIterator {
|
|
|
|
public:
|
|
|
|
using iterator_category = std::input_iterator_tag;
|
|
|
|
using value_type = absl::string_view;
|
|
|
|
using difference_type = ptrdiff_t;
|
|
|
|
using pointer = const value_type*;
|
|
|
|
using reference = value_type;
|
|
|
|
|
|
|
|
ChunkIterator() = default;
|
|
|
|
|
|
|
|
ChunkIterator& operator++();
|
|
|
|
ChunkIterator operator++(int);
|
|
|
|
bool operator==(const ChunkIterator& other) const;
|
|
|
|
bool operator!=(const ChunkIterator& other) const;
|
|
|
|
reference operator*() const;
|
|
|
|
pointer operator->() const;
|
|
|
|
|
|
|
|
friend class Cord;
|
|
|
|
friend class CharIterator;
|
|
|
|
|
|
|
|
private:
|
|
|
|
using CordRep = absl::cord_internal::CordRep;
|
|
|
|
using CordRepBtree = absl::cord_internal::CordRepBtree;
|
|
|
|
using CordRepBtreeReader = absl::cord_internal::CordRepBtreeReader;
|
|
|
|
|
|
|
|
// Stack of right children of concat nodes that we have to visit.
|
|
|
|
// Keep this at the end of the structure to avoid cache-thrashing.
|
|
|
|
// TODO(jgm): Benchmark to see if there's a more optimal value than 47 for
|
|
|
|
// 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);
|
|
|
|
Cord AdvanceAndReadBytes(size_t n);
|
|
|
|
void AdvanceBytes(size_t n);
|
|
|
|
|
|
|
|
// Stack specific operator++
|
|
|
|
ChunkIterator& AdvanceStack();
|
|
|
|
|
|
|
|
// Btree specific operator++
|
|
|
|
ChunkIterator& AdvanceBtree();
|
|
|
|
void AdvanceBytesBtree(size_t n);
|
|
|
|
|
|
|
|
// Iterates `n` bytes, where `n` is expected to be greater than or equal to
|
|
|
|
// `current_chunk_.size()`.
|
|
|
|
void AdvanceBytesSlowPath(size_t n);
|
|
|
|
|
|
|
|
// A view into bytes of the current `CordRep`. It may only be a view to a
|
|
|
|
// suffix of bytes if this is being used by `CharIterator`.
|
|
|
|
absl::string_view current_chunk_;
|
|
|
|
// The current leaf, or `nullptr` if the iterator points to short data.
|
|
|
|
// If the current chunk is a substring node, current_leaf_ points to the
|
|
|
|
// underlying flat or external node.
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Cord reader for cord btrees. Empty if not traversing a btree.
|
|
|
|
CordRepBtreeReader btree_reader_;
|
|
|
|
|
|
|
|
// See 'Stack' alias definition.
|
|
|
|
Stack stack_of_right_children_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Cord::ChunkIterator::chunk_begin()
|
|
|
|
//
|
|
|
|
// Returns an iterator to the first chunk of the `Cord`.
|
|
|
|
//
|
|
|
|
// Generally, prefer using `Cord::Chunks()` within a range-based for loop for
|
|
|
|
// iterating over the chunks of a Cord. This method may be useful for getting
|
|
|
|
// a `ChunkIterator` where range-based for-loops are not useful.
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// absl::Cord::ChunkIterator FindAsChunk(const absl::Cord& c,
|
|
|
|
// absl::string_view s) {
|
|
|
|
// return std::find(c.chunk_begin(), c.chunk_end(), s);
|
|
|
|
// }
|
|
|
|
ChunkIterator chunk_begin() const;
|
|
|
|
|
|
|
|
// Cord::ChunkItertator::chunk_end()
|
|
|
|
//
|
|
|
|
// Returns an iterator one increment past the last chunk of the `Cord`.
|
|
|
|
//
|
|
|
|
// Generally, prefer using `Cord::Chunks()` within a range-based for loop for
|
|
|
|
// iterating over the chunks of a Cord. This method may be useful for getting
|
|
|
|
// a `ChunkIterator` where range-based for-loops may not be available.
|
|
|
|
ChunkIterator chunk_end() const;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Cord::ChunkIterator::ChunkRange
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// `ChunkRange` is a helper class for iterating over the chunks of the `Cord`,
|
|
|
|
// producing an iterator which can be used within a range-based for loop.
|
|
|
|
// Construction of a `ChunkRange` will return an iterator pointing to the
|
|
|
|
// first chunk of the Cord. Generally, do not construct a `ChunkRange`
|
|
|
|
// directly; instead, prefer to use the `Cord::Chunks()` method.
|
|
|
|
//
|
|
|
|
// Implementation note: `ChunkRange` is simply a convenience wrapper over
|
|
|
|
// `Cord::chunk_begin()` and `Cord::chunk_end()`.
|
|
|
|
class ChunkRange {
|
|
|
|
public:
|
Export of internal Abseil changes
--
f49e405201d2ffd5955503fa8ad0f08ec0cdfb2b by Martijn Vels <mvels@google.com>:
Add common [container.requirements] type definitions to `CharRange` and `ChunkRange`
The presence of these allow these range classes to be used in various utility functions which require some minimum type of container. For example, this change allows tests to use `EXPECT_THAT(cord.Chunks(), ElementsAre(...))`
PiperOrigin-RevId: 406941278
--
0c195f073632e21d9a4bce158047b2ba8551c2d1 by Evan Brown <ezb@google.com>:
Use explicit exponential growth in SubstituteAndAppendArray.
PiperOrigin-RevId: 406931952
--
afb043bccd809a55cab78abadb7548a057d9eda0 by Jorg Brown <jorg@google.com>:
Use longer var names in macro to avoid clang-tidy warning
PiperOrigin-RevId: 406930978
--
80397e2604e6b3d929a34742c3a32581b34d3ac4 by Martijn Vels <mvels@google.com>:
Add future kAppendBuffer and kPrependBuffer API trackers for Cordz sampling
PiperOrigin-RevId: 406912759
--
e910ce919ef83933f08a690e8b7325c7cc5b6d5d by Martijn Vels <mvels@google.com>:
Implement Prepend(string_view) in terms of PrependArray(string_view, MethodIdentifier).
PiperOrigin-RevId: 406891665
--
c9cff43d4c0568ed01f2fca0f6ef038ae03112b5 by Martijn Vels <mvels@google.com>:
Add 'Rebuild' logic to CordRepBtree
There are btree hostile scenarios where an application could perform repeated split/insert/merge operations on a cord leading to a tree exceeding the maximum height. While this should be rare in practice, this change adds a Rebuild() method that will rebuild a tree with a 100% fill factor, and we will invoke this rebuild when a tree exceeds the maximum height. This basically follows the similar 'balance' logic in Concat trees (although the latter is common in Concat uses)
PiperOrigin-RevId: 406875739
--
5b2b8fb88f1ebfdc1c670088152da2cb2ea4c376 by Martijn Vels <mvels@google.com>:
Add 'in place' enabled RemoveSuffix
An in-place RemoveSuffix is more efficient than SubTree() as it can directly modify privately owned nodes and flats allowing easy re-use of free capacity in right-most flats that may turn into Substring edges when using SubTree.
PiperOrigin-RevId: 406431230
--
f09903c0a3d7344f59aaf1380a16ea10829217d4 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 406430373
--
9957af575c33bb18dc170572a4ee8cc5901df6b2 by Greg Falcon <gfalcon@google.com>:
Initial groundwork to allow storing checksum data inside CordRep instances.
This uses a RefcountAndFlags bit that was reserved for this purpose, and will be leveraged in a follow-up change to allow attaching checksums to a Cord's value.
This change splits RefcountAndFlags::IsOne() into two distinct operations:
* IsOne(): This returns true when the associated CordRep is not shared with other threads. This is useful for functions that consume CordRep instances; for example, code that consumes an unshared CordRep can assume ownership of its children without modifying those refcounts.
* IsMutable(): This returns true when the associated CordRep reference is not shared with other threads, *and* does not store an associated checksum value. This is useful for functions that modify a CordRep's contents: code may modify the bytes of a mutable-unshared CordRep without fear of races with other threads, or of invalidating a stored checksum.
The tricky part of this CL is ensuring that the correct choice between IsMutable() and IsOne() was made at each point. An incorrect application of IsOne() could lead to correctness bugs in the future. Code conditioned on IsOne() may delete the CordRep in question, or assume ownership of its children, but must not modify the CordRep's data without explicitly adjusting the CRC.
PiperOrigin-RevId: 406191103
--
686544814079e5ab6d4593cca0c068b510be400a by Martijn Vels <mvels@google.com>:
Reduce the size in the LargeString test when running with Sanitizers
PiperOrigin-RevId: 406186945
--
735b4490bdb695c35731f06ce4b8de14ce2be6ed by Alex Strelnikov <strel@google.com>:
Release absl::SimpleHexAtoi.
PiperOrigin-RevId: 406143188
GitOrigin-RevId: f49e405201d2ffd5955503fa8ad0f08ec0cdfb2b
Change-Id: Ic6527ac40fa03ea02ca813e8bb7868a219544de4
3 years ago
|
|
|
// Fulfill minimum c++ container requirements [container.requirements]
|
|
|
|
// Theses (partial) container type definitions allow ChunkRange to be used
|
|
|
|
// in various utilities expecting a subset of [container.requirements].
|
|
|
|
// For example, the below enables using `::testing::ElementsAre(...)`
|
|
|
|
using value_type = absl::string_view;
|
|
|
|
using reference = value_type&;
|
|
|
|
using const_reference = const value_type&;
|
|
|
|
using iterator = ChunkIterator;
|
|
|
|
using const_iterator = ChunkIterator;
|
|
|
|
|
|
|
|
explicit ChunkRange(const Cord* cord) : cord_(cord) {}
|
|
|
|
|
|
|
|
ChunkIterator begin() const;
|
|
|
|
ChunkIterator end() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Cord* cord_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Cord::Chunks()
|
|
|
|
//
|
|
|
|
// Returns a `Cord::ChunkIterator::ChunkRange` for iterating over the chunks
|
|
|
|
// of a `Cord` with a range-based for-loop. For most iteration tasks on a
|
|
|
|
// Cord, use `Cord::Chunks()` to retrieve this iterator.
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// void ProcessChunks(const Cord& cord) {
|
|
|
|
// for (absl::string_view chunk : cord.Chunks()) { ... }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// Note that the ordinary caveats of temporary lifetime extension apply:
|
|
|
|
//
|
|
|
|
// void Process() {
|
|
|
|
// for (absl::string_view chunk : CordFactory().Chunks()) {
|
|
|
|
// // The temporary Cord returned by CordFactory has been destroyed!
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
ChunkRange Chunks() const;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Cord::CharIterator
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// A `Cord::CharIterator` allows iteration over the constituent characters of
|
|
|
|
// a `Cord`.
|
|
|
|
//
|
|
|
|
// Generally, you do not instantiate a `Cord::CharIterator` directly; instead,
|
|
|
|
// you create one implicitly through use of the `Cord::Chars()` member
|
|
|
|
// function.
|
|
|
|
//
|
|
|
|
// A `Cord::CharIterator` has the following properties:
|
|
|
|
//
|
|
|
|
// * The iterator is invalidated after any non-const operation on the
|
|
|
|
// Cord object over which it iterates.
|
|
|
|
// * Two `CharIterator` objects can be compared equal if and only if they
|
|
|
|
// remain valid and iterate over the same Cord.
|
|
|
|
// * The iterator keeps state that can grow for Cords that contain many
|
|
|
|
// nodes and are imbalanced due to sharing. Prefer to pass this type by
|
|
|
|
// const reference instead of by value.
|
|
|
|
// * This type cannot act as a forward iterator because a `Cord` can reuse
|
|
|
|
// sections of memory. This fact violates the requirement for forward
|
|
|
|
// iterators to compare equal if dereferencing them returns the same
|
|
|
|
// object.
|
|
|
|
class CharIterator {
|
|
|
|
public:
|
|
|
|
using iterator_category = std::input_iterator_tag;
|
|
|
|
using value_type = char;
|
|
|
|
using difference_type = ptrdiff_t;
|
|
|
|
using pointer = const char*;
|
|
|
|
using reference = const char&;
|
|
|
|
|
|
|
|
CharIterator() = default;
|
|
|
|
|
|
|
|
CharIterator& operator++();
|
|
|
|
CharIterator operator++(int);
|
|
|
|
bool operator==(const CharIterator& other) const;
|
|
|
|
bool operator!=(const CharIterator& other) const;
|
|
|
|
reference operator*() const;
|
|
|
|
pointer operator->() const;
|
|
|
|
|
|
|
|
friend Cord;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit CharIterator(const Cord* cord) : chunk_iterator_(cord) {}
|
|
|
|
|
|
|
|
ChunkIterator chunk_iterator_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Cord::CharIterator::AdvanceAndRead()
|
|
|
|
//
|
|
|
|
// Advances the `Cord::CharIterator` by `n_bytes` and returns the bytes
|
|
|
|
// advanced as a separate `Cord`. `n_bytes` must be less than or equal to the
|
|
|
|
// number of bytes within the Cord; otherwise, behavior is undefined. It is
|
|
|
|
// valid to pass `char_end()` and `0`.
|
|
|
|
static Cord AdvanceAndRead(CharIterator* it, size_t n_bytes);
|
|
|
|
|
|
|
|
// Cord::CharIterator::Advance()
|
|
|
|
//
|
|
|
|
// Advances the `Cord::CharIterator` by `n_bytes`. `n_bytes` must be less than
|
|
|
|
// or equal to the number of bytes remaining within the Cord; otherwise,
|
|
|
|
// behavior is undefined. It is valid to pass `char_end()` and `0`.
|
|
|
|
static void Advance(CharIterator* it, size_t n_bytes);
|
|
|
|
|
|
|
|
// Cord::CharIterator::ChunkRemaining()
|
|
|
|
//
|
|
|
|
// Returns the longest contiguous view starting at the iterator's position.
|
|
|
|
//
|
|
|
|
// `it` must be dereferenceable.
|
|
|
|
static absl::string_view ChunkRemaining(const CharIterator& it);
|
|
|
|
|
|
|
|
// Cord::CharIterator::char_begin()
|
|
|
|
//
|
|
|
|
// Returns an iterator to the first character of the `Cord`.
|
|
|
|
//
|
|
|
|
// Generally, prefer using `Cord::Chars()` within a range-based for loop for
|
|
|
|
// iterating over the chunks of a Cord. This method may be useful for getting
|
|
|
|
// a `CharIterator` where range-based for-loops may not be available.
|
|
|
|
CharIterator char_begin() const;
|
|
|
|
|
|
|
|
// Cord::CharIterator::char_end()
|
|
|
|
//
|
|
|
|
// Returns an iterator to one past the last character of the `Cord`.
|
|
|
|
//
|
|
|
|
// Generally, prefer using `Cord::Chars()` within a range-based for loop for
|
|
|
|
// iterating over the chunks of a Cord. This method may be useful for getting
|
|
|
|
// a `CharIterator` where range-based for-loops are not useful.
|
|
|
|
CharIterator char_end() const;
|
|
|
|
|
|
|
|
// Cord::CharIterator::CharRange
|
|
|
|
//
|
|
|
|
// `CharRange` is a helper class for iterating over the characters of a
|
|
|
|
// producing an iterator which can be used within a range-based for loop.
|
|
|
|
// Construction of a `CharRange` will return an iterator pointing to the first
|
|
|
|
// character of the Cord. Generally, do not construct a `CharRange` directly;
|
|
|
|
// instead, prefer to use the `Cord::Chars()` method show below.
|
|
|
|
//
|
|
|
|
// Implementation note: `CharRange` is simply a convenience wrapper over
|
|
|
|
// `Cord::char_begin()` and `Cord::char_end()`.
|
|
|
|
class CharRange {
|
|
|
|
public:
|
Export of internal Abseil changes
--
f49e405201d2ffd5955503fa8ad0f08ec0cdfb2b by Martijn Vels <mvels@google.com>:
Add common [container.requirements] type definitions to `CharRange` and `ChunkRange`
The presence of these allow these range classes to be used in various utility functions which require some minimum type of container. For example, this change allows tests to use `EXPECT_THAT(cord.Chunks(), ElementsAre(...))`
PiperOrigin-RevId: 406941278
--
0c195f073632e21d9a4bce158047b2ba8551c2d1 by Evan Brown <ezb@google.com>:
Use explicit exponential growth in SubstituteAndAppendArray.
PiperOrigin-RevId: 406931952
--
afb043bccd809a55cab78abadb7548a057d9eda0 by Jorg Brown <jorg@google.com>:
Use longer var names in macro to avoid clang-tidy warning
PiperOrigin-RevId: 406930978
--
80397e2604e6b3d929a34742c3a32581b34d3ac4 by Martijn Vels <mvels@google.com>:
Add future kAppendBuffer and kPrependBuffer API trackers for Cordz sampling
PiperOrigin-RevId: 406912759
--
e910ce919ef83933f08a690e8b7325c7cc5b6d5d by Martijn Vels <mvels@google.com>:
Implement Prepend(string_view) in terms of PrependArray(string_view, MethodIdentifier).
PiperOrigin-RevId: 406891665
--
c9cff43d4c0568ed01f2fca0f6ef038ae03112b5 by Martijn Vels <mvels@google.com>:
Add 'Rebuild' logic to CordRepBtree
There are btree hostile scenarios where an application could perform repeated split/insert/merge operations on a cord leading to a tree exceeding the maximum height. While this should be rare in practice, this change adds a Rebuild() method that will rebuild a tree with a 100% fill factor, and we will invoke this rebuild when a tree exceeds the maximum height. This basically follows the similar 'balance' logic in Concat trees (although the latter is common in Concat uses)
PiperOrigin-RevId: 406875739
--
5b2b8fb88f1ebfdc1c670088152da2cb2ea4c376 by Martijn Vels <mvels@google.com>:
Add 'in place' enabled RemoveSuffix
An in-place RemoveSuffix is more efficient than SubTree() as it can directly modify privately owned nodes and flats allowing easy re-use of free capacity in right-most flats that may turn into Substring edges when using SubTree.
PiperOrigin-RevId: 406431230
--
f09903c0a3d7344f59aaf1380a16ea10829217d4 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 406430373
--
9957af575c33bb18dc170572a4ee8cc5901df6b2 by Greg Falcon <gfalcon@google.com>:
Initial groundwork to allow storing checksum data inside CordRep instances.
This uses a RefcountAndFlags bit that was reserved for this purpose, and will be leveraged in a follow-up change to allow attaching checksums to a Cord's value.
This change splits RefcountAndFlags::IsOne() into two distinct operations:
* IsOne(): This returns true when the associated CordRep is not shared with other threads. This is useful for functions that consume CordRep instances; for example, code that consumes an unshared CordRep can assume ownership of its children without modifying those refcounts.
* IsMutable(): This returns true when the associated CordRep reference is not shared with other threads, *and* does not store an associated checksum value. This is useful for functions that modify a CordRep's contents: code may modify the bytes of a mutable-unshared CordRep without fear of races with other threads, or of invalidating a stored checksum.
The tricky part of this CL is ensuring that the correct choice between IsMutable() and IsOne() was made at each point. An incorrect application of IsOne() could lead to correctness bugs in the future. Code conditioned on IsOne() may delete the CordRep in question, or assume ownership of its children, but must not modify the CordRep's data without explicitly adjusting the CRC.
PiperOrigin-RevId: 406191103
--
686544814079e5ab6d4593cca0c068b510be400a by Martijn Vels <mvels@google.com>:
Reduce the size in the LargeString test when running with Sanitizers
PiperOrigin-RevId: 406186945
--
735b4490bdb695c35731f06ce4b8de14ce2be6ed by Alex Strelnikov <strel@google.com>:
Release absl::SimpleHexAtoi.
PiperOrigin-RevId: 406143188
GitOrigin-RevId: f49e405201d2ffd5955503fa8ad0f08ec0cdfb2b
Change-Id: Ic6527ac40fa03ea02ca813e8bb7868a219544de4
3 years ago
|
|
|
// Fulfill minimum c++ container requirements [container.requirements]
|
|
|
|
// Theses (partial) container type definitions allow CharRange to be used
|
|
|
|
// in various utilities expecting a subset of [container.requirements].
|
|
|
|
// For example, the below enables using `::testing::ElementsAre(...)`
|
|
|
|
using value_type = char;
|
|
|
|
using reference = value_type&;
|
|
|
|
using const_reference = const value_type&;
|
|
|
|
using iterator = CharIterator;
|
|
|
|
using const_iterator = CharIterator;
|
|
|
|
|
|
|
|
explicit CharRange(const Cord* cord) : cord_(cord) {}
|
|
|
|
|
|
|
|
CharIterator begin() const;
|
|
|
|
CharIterator end() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Cord* cord_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Cord::CharIterator::Chars()
|
|
|
|
//
|
|
|
|
// Returns a `Cord::CharIterator` for iterating over the characters of a
|
|
|
|
// `Cord` with a range-based for-loop. For most character-based iteration
|
|
|
|
// tasks on a Cord, use `Cord::Chars()` to retrieve this iterator.
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// void ProcessCord(const Cord& cord) {
|
|
|
|
// for (char c : cord.Chars()) { ... }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// Note that the ordinary caveats of temporary lifetime extension apply:
|
|
|
|
//
|
|
|
|
// void Process() {
|
|
|
|
// for (char c : CordFactory().Chars()) {
|
|
|
|
// // The temporary Cord returned by CordFactory has been destroyed!
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
CharRange Chars() const;
|
|
|
|
|
|
|
|
// Cord::operator[]
|
|
|
|
//
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// Gets the "i"th character of the Cord and returns it, provided that
|
|
|
|
// 0 <= i < Cord.size().
|
|
|
|
//
|
|
|
|
// NOTE: This routine is reasonably efficient. It is roughly
|
|
|
|
// logarithmic based on the number of chunks that make up the cord. Still,
|
|
|
|
// if you need to iterate over the contents of a cord, you should
|
|
|
|
// use a CharIterator/ChunkIterator rather than call operator[] or Get()
|
|
|
|
// repeatedly in a loop.
|
|
|
|
char operator[](size_t i) const;
|
|
|
|
|
|
|
|
// Cord::TryFlat()
|
|
|
|
//
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// If this cord's representation is a single flat array, returns a
|
|
|
|
// string_view referencing that array. Otherwise returns nullopt.
|
|
|
|
absl::optional<absl::string_view> TryFlat() const;
|
|
|
|
|
|
|
|
// Cord::Flatten()
|
|
|
|
//
|
|
|
|
// Flattens the cord into a single array and returns a view of the data.
|
|
|
|
//
|
|
|
|
// If the cord was already flat, the contents are not modified.
|
|
|
|
absl::string_view Flatten();
|
|
|
|
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// Supports absl::Cord as a sink object for absl::Format().
|
|
|
|
friend void AbslFormatFlush(absl::Cord* cord, absl::string_view part) {
|
|
|
|
cord->Append(part);
|
|
|
|
}
|
|
|
|
|
Export of internal Abseil changes
--
83e4cdf03a4d702b30e69204060de09e462e23c6 by Greg Falcon <gfalcon@google.com>:
Revert the crc addition to RefcountAndFlags, and restore related comments to their original state.
In development, the implementation of SetExpectedCrc() changed, and there is no longer a need to track the CRC status in the refcount.
Since the distinction between IsOne() and IsMutable() is subtle *and unused*, removing it now can help avoid subtle bugs in the future. This distinction can always be added back later, if it proves necessary.
Keep the reserved bit for now; all it costs is one extra mask instruction in the refcount checks, and space for extra state in Cord is always hard to find.
PiperOrigin-RevId: 408647038
--
ee67585cf66954176615271f50f8b278119dd138 by Greg Falcon <gfalcon@google.com>:
Implement Cord::SetExpectedChecksum() and Cord::ExpectedChecksum().
SetExpectedChecksum() will store a uint32_t out-of-band alongside a Cord's data. This value persists through copies and assignments. Mutating operations on a Cord cause the value to be forgotten. ExpectedChecksum() retrieves the stored value, if present.
This API is intended for storing a CRC32C checksum alongside data, allowing checksums to be passed through dataflows and validated at the final step. However, this API is agnostic to the meaning of the stored value. No CRC32C validation is performed by these new APIs.
This implementation adds a new CordRep node, CordRepCrc. A CordRepCrc may (currently) only live at the top of a tree. This allows traversal logic to be agnostic to these nodes, instead putting the needed branches at the mutation level. This also implements the property requested from API review, that any mutation is guaranteed to permanently forget the stored CRC.
PiperOrigin-RevId: 408611221
--
a86f592402b37c854ebdc77d2b9b425451a7a675 by Martijn Vels <mvels@google.com>:
Move 'ExtractResult' into CordRep
The result of an extract operation is logically identical for any tree implementation, and having a single type makes 'tree independent' implementation in cord.cc more concise.
PiperOrigin-RevId: 408332408
--
baa7647e21db59a87f75af9cac62172ce38a0f71 by Abseil Team <absl-team@google.com>:
Replace usages of `assert` macros with `ABSL_HARDENING_ASSERT`.
PiperOrigin-RevId: 408272133
--
c7658133d8662c39fa5035fc93a364c7c3d327e0 by Martijn Vels <mvels@google.com>:
Add CordRepBtree::ExtractAppendBuffer
PiperOrigin-RevId: 407944179
--
5775100363b5890ebfe710fadebf040445eab991 by Martijn Vels <mvels@google.com>:
Add CordRepConcat::ExtractAppendBuffer
PiperOrigin-RevId: 407932968
--
9f520ba1600a93352c78f644a369c7c76195ee86 by Greg Falcon <gfalcon@google.com>:
Add cordz tracking for crc nodes.
This also adds a new kSetExpectedChecksum method to the list of tracked methods. This is presently unused but will be used soon.
PiperOrigin-RevId: 407884120
GitOrigin-RevId: 83e4cdf03a4d702b30e69204060de09e462e23c6
Change-Id: I134ace2d87215813eaa60a282996a33884676c06
3 years ago
|
|
|
// Cord::SetExpectedChecksum()
|
|
|
|
//
|
|
|
|
// Stores a checksum value with this non-empty cord instance, for later
|
|
|
|
// retrieval.
|
|
|
|
//
|
|
|
|
// The expected checksum is a number stored out-of-band, alongside the data.
|
|
|
|
// It is preserved across copies and assignments, but any mutations to a cord
|
|
|
|
// will cause it to lose its expected checksum.
|
|
|
|
//
|
|
|
|
// The expected checksum is not part of a Cord's value, and does not affect
|
|
|
|
// operations such as equality or hashing.
|
|
|
|
//
|
|
|
|
// This field is intended to store a CRC32C checksum for later validation, to
|
|
|
|
// help support end-to-end checksum workflows. However, the Cord API itself
|
|
|
|
// does no CRC validation, and assigns no meaning to this number.
|
|
|
|
//
|
|
|
|
// This call has no effect if this cord is empty.
|
|
|
|
void SetExpectedChecksum(uint32_t crc);
|
|
|
|
|
|
|
|
// Returns this cord's expected checksum, if it has one. Otherwise, returns
|
|
|
|
// nullopt.
|
|
|
|
absl::optional<uint32_t> ExpectedChecksum() const;
|
|
|
|
|
|
|
|
template <typename H>
|
|
|
|
friend H AbslHashValue(H hash_state, const absl::Cord& c) {
|
|
|
|
absl::optional<absl::string_view> maybe_flat = c.TryFlat();
|
|
|
|
if (maybe_flat.has_value()) {
|
|
|
|
return H::combine(std::move(hash_state), *maybe_flat);
|
|
|
|
}
|
|
|
|
return c.HashFragmented(std::move(hash_state));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a Cord with the contents of StringConstant<T>::value.
|
|
|
|
// No allocations will be done and no data will be copied.
|
|
|
|
// This is an INTERNAL API and subject to change or removal. This API can only
|
|
|
|
// be used by spelling absl::strings_internal::MakeStringConstant, which is
|
|
|
|
// also an internal API.
|
|
|
|
template <typename T>
|
|
|
|
explicit constexpr Cord(strings_internal::StringConstant<T>);
|
|
|
|
|
|
|
|
private:
|
|
|
|
using CordRep = absl::cord_internal::CordRep;
|
|
|
|
using CordRepFlat = absl::cord_internal::CordRepFlat;
|
|
|
|
using CordzInfo = cord_internal::CordzInfo;
|
|
|
|
using CordzUpdateScope = cord_internal::CordzUpdateScope;
|
Export of internal Abseil changes
--
ac1df60490c9583e475e22de7adfc40023196fbf by Martijn Vels <mvels@google.com>:
Change Cord constructor(string_view) to explicit make_tree and Cordz tracking
This CL changes the ctor to use an easier to maintain model where Cord code explicitly invokes Cordz update or new / tree logic, which avoids the ambiguity of the 'branched' InlineRep::set_tree code. This removes the need to equip InlineRep with 'MethodIdentifier' or other necessary call info, and also is a cleaner model: InlineRep is carrying too much code now that should plainly sit in Cord, especially with all internal abstractions having moved to InlineData.
See child CL(s) for desired state
PiperOrigin-RevId: 369433619
--
b665af7f586e6c679a8b27d4f78d5a1d2b596058 by Abseil Team <absl-team@google.com>:
Rename the 'Compare' template type to 'LessThan', as the passed-in function is expected to act like operator<. It is worth avoiding confusion with std::compare, which returns an int (-1/0/1), as due to implicit casting this can lead to hard-to-spot bugs.
PiperOrigin-RevId: 369391118
--
c3c775269cad0f4982ec63f3616dd78bb9e52dca by Martijn Vels <mvels@google.com>:
Integrate CordzUpdateTracker into CordzInfo
PiperOrigin-RevId: 369348824
--
771d81ed357496c117179e1daec76eba5155932d by Martijn Vels <mvels@google.com>:
Replace mutex() with Lock() / Unlock() function
Mini design future tracking of CordzInfo sampled cords: CordzInfo holds a CordRep* reference without a reference count. Cord is responsible for synchronizing updates for sampled cords such that the CordRep* contained in CordzInfo is at all times valid. This is done by scoping Lock() and Unlock() calls around the code modifying the code of a sampled cord. For example (using the future CL CordzUpdateScope()):
CordzInfo* cordz_info = get_cordz_info();
CordzUpdateScope scope(cordz_info, CordzUpdateTracker::kRemovePrefix);
CordRep* rep = RemovePrefixImpl(root);
set_tree(rep);
if (cordz_info) {
cordz_info->SetCordRep(rep);
}
On CordzInfo::Unlock(), if the internal rep is null, the cord is no longer sampled, and CordzInfo will be deleted. Thus any update resulting in the Cord being inlined will automatically no longer be sampled.
PiperOrigin-RevId: 369338802
--
5563c12df04a1e965a03b50bdd032739c55c0706 by Martijn Vels <mvels@google.com>:
Add UpdateTracker to CordzStatistics
PiperOrigin-RevId: 369318178
--
6b4d8463722a3e55a3e8f6cb3741a41055e7f83e by Martijn Vels <mvels@google.com>:
Add kClear, kConstructor* and kUnknown values and fix typo
PiperOrigin-RevId: 369297163
--
041adcbc929789d6d53371a8236840fc350e1eeb by Derek Mauro <dmauro@google.com>:
Switch from malloc to operator new in pool_urbg.cc
so it can only fail by throwing/aborting
PiperOrigin-RevId: 369274087
--
5d97a5f43e3f2d02d0a5bbe586d93b5751812981 by Benjamin Barenblat <bbaren@google.com>:
Correct Thumb function bound computation in the symbolizer
On 32-bit ARM, all functions are aligned to multiples of two bytes, and
the lowest-order bit in a function’s address is ignored by the CPU when
computing branch targets. That bit is still present in instructions and
ELF symbol tables, though; it’s repurposed to indicate whether the
function contains ARM or Thumb code. If the symbolizer doesn’t ignore
that bit, it will believe Thumb functions have boundaries that are off
by one byte, so instruct the symbolizer to null out the lowest-order bit
after retrieving it from the symbol table.
PiperOrigin-RevId: 369254082
--
462bb307c6cc332c1e2c3adb5f0cad51804bf937 by Derek Mauro <dmauro@google.com>:
Add a check for malloc failure in pool_urbg.cc
GitHub #940
PiperOrigin-RevId: 369238100
GitOrigin-RevId: ac1df60490c9583e475e22de7adfc40023196fbf
Change-Id: Ic6ec91c62cd3a0031f6a75a43a83da959ece2d25
4 years ago
|
|
|
using CordzUpdateTracker = cord_internal::CordzUpdateTracker;
|
|
|
|
using InlineData = cord_internal::InlineData;
|
|
|
|
using MethodIdentifier = CordzUpdateTracker::MethodIdentifier;
|
Export of internal Abseil changes
--
ac1df60490c9583e475e22de7adfc40023196fbf by Martijn Vels <mvels@google.com>:
Change Cord constructor(string_view) to explicit make_tree and Cordz tracking
This CL changes the ctor to use an easier to maintain model where Cord code explicitly invokes Cordz update or new / tree logic, which avoids the ambiguity of the 'branched' InlineRep::set_tree code. This removes the need to equip InlineRep with 'MethodIdentifier' or other necessary call info, and also is a cleaner model: InlineRep is carrying too much code now that should plainly sit in Cord, especially with all internal abstractions having moved to InlineData.
See child CL(s) for desired state
PiperOrigin-RevId: 369433619
--
b665af7f586e6c679a8b27d4f78d5a1d2b596058 by Abseil Team <absl-team@google.com>:
Rename the 'Compare' template type to 'LessThan', as the passed-in function is expected to act like operator<. It is worth avoiding confusion with std::compare, which returns an int (-1/0/1), as due to implicit casting this can lead to hard-to-spot bugs.
PiperOrigin-RevId: 369391118
--
c3c775269cad0f4982ec63f3616dd78bb9e52dca by Martijn Vels <mvels@google.com>:
Integrate CordzUpdateTracker into CordzInfo
PiperOrigin-RevId: 369348824
--
771d81ed357496c117179e1daec76eba5155932d by Martijn Vels <mvels@google.com>:
Replace mutex() with Lock() / Unlock() function
Mini design future tracking of CordzInfo sampled cords: CordzInfo holds a CordRep* reference without a reference count. Cord is responsible for synchronizing updates for sampled cords such that the CordRep* contained in CordzInfo is at all times valid. This is done by scoping Lock() and Unlock() calls around the code modifying the code of a sampled cord. For example (using the future CL CordzUpdateScope()):
CordzInfo* cordz_info = get_cordz_info();
CordzUpdateScope scope(cordz_info, CordzUpdateTracker::kRemovePrefix);
CordRep* rep = RemovePrefixImpl(root);
set_tree(rep);
if (cordz_info) {
cordz_info->SetCordRep(rep);
}
On CordzInfo::Unlock(), if the internal rep is null, the cord is no longer sampled, and CordzInfo will be deleted. Thus any update resulting in the Cord being inlined will automatically no longer be sampled.
PiperOrigin-RevId: 369338802
--
5563c12df04a1e965a03b50bdd032739c55c0706 by Martijn Vels <mvels@google.com>:
Add UpdateTracker to CordzStatistics
PiperOrigin-RevId: 369318178
--
6b4d8463722a3e55a3e8f6cb3741a41055e7f83e by Martijn Vels <mvels@google.com>:
Add kClear, kConstructor* and kUnknown values and fix typo
PiperOrigin-RevId: 369297163
--
041adcbc929789d6d53371a8236840fc350e1eeb by Derek Mauro <dmauro@google.com>:
Switch from malloc to operator new in pool_urbg.cc
so it can only fail by throwing/aborting
PiperOrigin-RevId: 369274087
--
5d97a5f43e3f2d02d0a5bbe586d93b5751812981 by Benjamin Barenblat <bbaren@google.com>:
Correct Thumb function bound computation in the symbolizer
On 32-bit ARM, all functions are aligned to multiples of two bytes, and
the lowest-order bit in a function’s address is ignored by the CPU when
computing branch targets. That bit is still present in instructions and
ELF symbol tables, though; it’s repurposed to indicate whether the
function contains ARM or Thumb code. If the symbolizer doesn’t ignore
that bit, it will believe Thumb functions have boundaries that are off
by one byte, so instruct the symbolizer to null out the lowest-order bit
after retrieving it from the symbol table.
PiperOrigin-RevId: 369254082
--
462bb307c6cc332c1e2c3adb5f0cad51804bf937 by Derek Mauro <dmauro@google.com>:
Add a check for malloc failure in pool_urbg.cc
GitHub #940
PiperOrigin-RevId: 369238100
GitOrigin-RevId: ac1df60490c9583e475e22de7adfc40023196fbf
Change-Id: Ic6ec91c62cd3a0031f6a75a43a83da959ece2d25
4 years ago
|
|
|
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
// Creates a cord instance with `method` representing the originating
|
|
|
|
// public API call causing the cord to be created.
|
|
|
|
explicit Cord(absl::string_view src, MethodIdentifier method);
|
|
|
|
|
|
|
|
friend class CordTestPeer;
|
|
|
|
friend bool operator==(const Cord& lhs, const Cord& rhs);
|
|
|
|
friend bool operator==(const Cord& lhs, absl::string_view rhs);
|
|
|
|
|
|
|
|
friend const CordzInfo* GetCordzInfoForTesting(const Cord& cord);
|
|
|
|
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// Calls the provided function once for each cord chunk, in order. Unlike
|
|
|
|
// Chunks(), this API will not allocate memory.
|
|
|
|
void ForEachChunk(absl::FunctionRef<void(absl::string_view)>) const;
|
|
|
|
|
|
|
|
// Allocates new contiguous storage for the contents of the cord. This is
|
|
|
|
// called by Flatten() when the cord was not already flat.
|
|
|
|
absl::string_view FlattenSlowPath();
|
|
|
|
|
|
|
|
// Actual cord contents are hidden inside the following simple
|
|
|
|
// class so that we can isolate the bulk of cord.cc from changes
|
|
|
|
// to the representation.
|
|
|
|
//
|
|
|
|
// InlineRep holds either a tree pointer, or an array of kMaxInline bytes.
|
|
|
|
class InlineRep {
|
|
|
|
public:
|
|
|
|
static constexpr unsigned char kMaxInline = cord_internal::kMaxInline;
|
|
|
|
static_assert(kMaxInline >= sizeof(absl::cord_internal::CordRep*), "");
|
|
|
|
|
|
|
|
constexpr InlineRep() : data_() {}
|
|
|
|
explicit InlineRep(InlineData::DefaultInitType init) : data_(init) {}
|
|
|
|
InlineRep(const InlineRep& src);
|
|
|
|
InlineRep(InlineRep&& src);
|
|
|
|
InlineRep& operator=(const InlineRep& src);
|
|
|
|
InlineRep& operator=(InlineRep&& src) noexcept;
|
|
|
|
|
|
|
|
explicit constexpr InlineRep(cord_internal::InlineData data);
|
|
|
|
|
|
|
|
void Swap(InlineRep* rhs);
|
|
|
|
bool empty() const;
|
|
|
|
size_t size() const;
|
|
|
|
const char* data() const; // Returns nullptr if holding pointer
|
Export of internal Abseil changes
--
07240ca7822d007cdcc79f2c40bd58b2c2010348 by Abseil Team <absl-team@google.com>:
Correct the comment from "AlphaNum" to "Arg".
PiperOrigin-RevId: 416139192
--
adcba4a6b3763626e1db7b1e8c108b3114903557 by Martijn Vels <mvels@google.com>:
Fix NewExternalRep() to require data being non-empty, and remove nullptr return.
PiperOrigin-RevId: 416135865
--
c0d14cd918fb16f15d1d84de9284b5c5ecc1f8f2 by Abseil Team <absl-team@google.com>:
Fix doc comment for absl::ascii_isprint().
The comment was incorrectly saying that it includes all whitespace.
It doesn't; the only whitespace char it includes is ' '.
PiperOrigin-RevId: 416112524
--
d83327800159c07002b6865e21232a12463e02dd by Abseil Team <absl-team@google.com>:
Internal change
PiperOrigin-RevId: 416099978
--
baf11e9ca42ca9140cdbf8075f971db8d65b1195 by Ilya Tokar <tokarip@google.com>:
Prevent compiler from optimizing Group_Match* benchmarks away.
Currently we benchmark single store of precomputed value.
Not all affected benchmarks show performance changes:
BM_Group_Match 0.53ns ± 1% 0.53ns ± 0% -0.42% (p=0.038 n=10+10)
BM_Group_MatchEmpty 0.26ns ± 1% 0.26ns ± 1% ~ (p=1.000 n=10+10)
BM_Group_MatchEmptyOrDeleted 0.26ns ± 1% 0.26ns ± 1% ~ (p=0.121 n=10+10)
BM_Group_CountLeadingEmptyOrDeleted 0.26ns ± 1% 0.45ns ± 0% +70.05% (p=0.000 n=10+8)
BM_Group_MatchFirstEmptyOrDeleted 0.26ns ± 0% 0.44ns ± 1% +65.91% (p=0.000 n=8+9)
But inspecting the generated code shows the difference,
e. g. BM_Group_MatchFirstEmptyOrDeleted
Before:
add $0xffffffffffffffff,%rbx
jne 30
After:
pcmpeqd %xmm0,%xmm0
pcmpgtb -0x30(%rbp),%xmm0
pmovmskb %xmm0,%eax
add: 0x23$0xffffffffffffffff,%rbx
jne 40
PiperOrigin-RevId: 416083515
--
122fbff893dc4571b3e75e4b241eb4495b925610 by Abseil Team <absl-team@google.com>:
Put namespace guard in ABSL_DECLARE_FLAG to make declaring a flag in a namespace a compiler error instead of a linker error.
PiperOrigin-RevId: 416036072
--
020fd8a20f5fa319e948846e003391fcb9e03868 by Ilya Tokar <tokarip@google.com>:
Make Cord::InlineRep::set_data unconditionally zero out memory.
Currently there is a single case where we don't zero out memory
as an optimization. Unconditional zeroing doesn't show any changes
in benchmarks, except for the unrelated improvement:
BM_CordPartialCopyToCord/1M/1 12.6ns ± 4% 12.6ns ± 4% ~ (p=0.857 n=16+19)
BM_CordPartialCopyToCord/1M/128 44.9ns ± 7% 45.0ns ± 3% ~ (p=0.468 n=18+17)
BM_CordPartialCopyToCord/1M/1k 64.5ns ± 4% 61.4ns ± 4% -4.82% (p=0.000 n=19+17)
BM_CordPartialCopyToCord/1M/8k 139ns ± 3% 128ns ±15% -7.76% (p=0.009 n=17+20)
BM_CordPartialCopyToCord/1M/16k 193ns ± 6% 168ns ± 6% -13.17% (p=0.000 n=17+17)
BM_CordPartialCopyToCord/4M/16k 199ns ± 4% 177ns ± 4% -11.36% (p=0.000 n=17+18)
BM_CordPartialCopyToCord/4M/32k 275ns ± 3% 250ns ± 4% -9.00% (p=0.000 n=18+18)
BM_CordPartialCopyToCord/4M/64k 291ns ± 4% 266ns ± 5% -8.53% (p=0.000 n=18+16)
BM_CordPartialCopyToCord/4M/128k 322ns ± 5% 291ns ± 4% -9.43% (p=0.000 n=20+18)
BM_CordPartialCopyToCord/8M/32k 281ns ± 5% 251ns ± 4% -10.38% (p=0.000 n=20+16)
BM_CordPartialCopyToCord/8M/64k 293ns ± 6% 267ns ± 4% -8.87% (p=0.000 n=16+19)
BM_CordPartialCopyToCord/8M/128k 334ns ± 3% 305ns ± 2% -8.56% (p=0.000 n=17+16)
This is clearly an alignmnet effect since number of the executed instructions is the same:
M_CordPartialCopyToCord/1M/1 155 ± 0% 155 ± 0% ~ (all samples are equal)
BM_CordPartialCopyToCord/1M/128 446 ± 0% 446 ± 0% ~ (p=0.332 n=36+39)
BM_CordPartialCopyToCord/1M/1k 473 ± 0% 473 ± 0% ~ (p=0.969 n=40+40)
BM_CordPartialCopyToCord/1M/8k 808 ± 0% 808 ± 0% ~ (p=0.127 n=40+39)
BM_CordPartialCopyToCord/1M/16k 957 ± 0% 957 ± 0% ~ (p=0.532 n=40+40)
BM_CordPartialCopyToCord/4M/16k 952 ± 0% 952 ± 0% ~ (p=0.686 n=39+39)
BM_CordPartialCopyToCord/4M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.690 n=40+40)
BM_CordPartialCopyToCord/4M/64k 1.23k ± 0% 1.23k ± 0% ~ (p=0.182 n=40+39)
BM_CordPartialCopyToCord/4M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.711 n=40+40)
BM_CordPartialCopyToCord/8M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.697 n=40+40)
BM_CordPartialCopyToCord/8M/64k 1.23k ± 0% 1.23k ± 0% +0.00% (p=0.049 n=40+40)
BM_CordPartialCopyToCord/8M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.507 n=40+40)
This makes code simpler and doesn't regress performance.
PiperOrigin-RevId: 415560574
--
37305b2690b31682088749e4d62f40d7095bdc54 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 415558737
--
86aaed569b9e743c1eb813a5f48def978a793db3 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415515201
--
6cdb8786cdcb4fa0b8a4b72fc98940877d1fdeff by Abseil Team <absl-team@google.com>:
Update SubmitMutexProfileData to accept wait_cycles instead of wait_timestamp
PiperOrigin-RevId: 415360871
--
9f979d307aa16ad09f214e04876cbe84395c0901 by Abseil Team <absl-team@google.com>:
absl::flat_hash_set compiles with -Wconversion -Wsign-compare
PiperOrigin-RevId: 415357498
--
9eceb14174708f15e61259d449b214a8a4c7f9e7 by Abseil Team <absl-team@google.com>:
Fix AddressIsReadable for the corner case of (aligned) addr == NULL.
PiperOrigin-RevId: 415307792
--
1a39ffe55898375e2d7f88c17c99db5a1b95b313 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415162872
--
64378549b110d5f5762185a5906c520fba70f0e7 by Abseil Team <absl-team@google.com>:
Fix a typo in the comments
PiperOrigin-RevId: 415088461
--
41aae8322e913b82710153c22b97c611fdb6e1fb by Abseil Team <absl-team@google.com>:
Switch from `connect` to `rt_sigreturn` -- the latter is much less problematic
for system call sandboxes.
PiperOrigin-RevId: 415073965
--
870c5e3388b6a35611bff538626fe7a1c8c87171 by Abseil Team <absl-team@google.com>:
Add ABSL_HAVE_HWADDRESS_SANITIZER and ABSL_HAVE_LEAK_SANITIZER
PiperOrigin-RevId: 414871189
--
f213ed60a66b58da7ac40555adfb1d529ff0a4db by Derek Mauro <dmauro@google.com>:
Remove reference to __SANITIZE_MEMORY__, which does not exist
It appears to have been copied by pattern matching from the ASAN/TSAN
code blocks.
https://github.com/gcc-mirror/gcc/blob/f47662204de27f7685699eeef89aa173ccf32d85/gcc/cppbuiltin.c#L79-L126
PiperOrigin-RevId: 414806587
--
b152891e73ab515f397ceb53f66c8ee2f33863ea by Abseil Team <absl-team@google.com>:
Rollback previous commit: SYS_open is not defined in certain environments.
PiperOrigin-RevId: 414521820
--
5a1cbb282331023902e1374dd0d920c4effbe47f by Abseil Team <absl-team@google.com>:
Use syscall(SYS_open, ...) instead of open() to avoid possible symbol
interposition.
Also add some warning notes.
PiperOrigin-RevId: 414508186
--
1824d6593612710aafdc599a89b0adced7d787f6 by Abseil Team <absl-team@google.com>:
Correct aarch64 macro check
The macro is __aarch64__, not __arch64__.
PiperOrigin-RevId: 414446225
--
a1536a57b64dfd53945d33a01cfc08b18c99c97b by Abseil Team <absl-team@google.com>:
Fix backwards comment in the last commit.
PiperOrigin-RevId: 414281214
--
11ac021ba779513667a31cf2563ddafc57d6d913 by Abseil Team <absl-team@google.com>:
AddressIsReadable() didn't work correctly on ARM when the given pointer was
misaligned at the end of the page.
Fix that by aligning the pointer on an 8-byte boundary before checking it.
PiperOrigin-RevId: 414203863
GitOrigin-RevId: 07240ca7822d007cdcc79f2c40bd58b2c2010348
Change-Id: If5f129194d59f5c9e5d84efd8cd9e17a70e072ab
3 years ago
|
|
|
void set_data(const char* data, size_t n); // Discards pointer, if any
|
|
|
|
char* set_data(size_t n); // Write data to the result
|
|
|
|
// Returns nullptr if holding bytes
|
|
|
|
absl::cord_internal::CordRep* tree() const;
|
|
|
|
absl::cord_internal::CordRep* as_tree() const;
|
|
|
|
// Returns non-null iff was holding a pointer
|
|
|
|
absl::cord_internal::CordRep* clear();
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// Converts to pointer if necessary.
|
|
|
|
void reduce_size(size_t n); // REQUIRES: holding data
|
|
|
|
void remove_prefix(size_t n); // REQUIRES: holding data
|
|
|
|
void AppendArray(absl::string_view src, MethodIdentifier method);
|
|
|
|
absl::string_view FindFlatStartPiece() const;
|
|
|
|
|
|
|
|
// Creates a CordRepFlat instance from the current inlined data with `extra'
|
|
|
|
// bytes of desired additional capacity.
|
|
|
|
CordRepFlat* MakeFlatWithExtraCapacity(size_t extra);
|
|
|
|
|
|
|
|
// Sets the tree value for this instance. `rep` must not be null.
|
|
|
|
// Requires the current instance to hold a tree, and a lock to be held on
|
|
|
|
// any CordzInfo referenced by this instance. The latter is enforced through
|
|
|
|
// the CordzUpdateScope argument. If the current instance is sampled, then
|
|
|
|
// the CordzInfo instance is updated to reference the new `rep` value.
|
|
|
|
void SetTree(CordRep* rep, const CordzUpdateScope& scope);
|
|
|
|
|
|
|
|
// Identical to SetTree(), except that `rep` is allowed to be null, in
|
|
|
|
// which case the current instance is reset to an empty value.
|
|
|
|
void SetTreeOrEmpty(CordRep* rep, const CordzUpdateScope& scope);
|
|
|
|
|
|
|
|
// Sets the tree value for this instance, and randomly samples this cord.
|
|
|
|
// This function disregards existing contents in `data_`, and should be
|
|
|
|
// called when a Cord is 'promoted' from an 'uninitialized' or 'inlined'
|
|
|
|
// value to a non-inlined (tree / ring) value.
|
|
|
|
void EmplaceTree(CordRep* rep, MethodIdentifier method);
|
|
|
|
|
|
|
|
// Identical to EmplaceTree, except that it copies the parent stack from
|
|
|
|
// the provided `parent` data if the parent is sampled.
|
|
|
|
void EmplaceTree(CordRep* rep, const InlineData& parent,
|
|
|
|
MethodIdentifier method);
|
|
|
|
|
|
|
|
// Commits the change of a newly created, or updated `rep` root value into
|
|
|
|
// this cord. `old_rep` indicates the old (inlined or tree) value of the
|
|
|
|
// cord, and determines if the commit invokes SetTree() or EmplaceTree().
|
|
|
|
void CommitTree(const CordRep* old_rep, CordRep* rep,
|
|
|
|
const CordzUpdateScope& scope, MethodIdentifier method);
|
|
|
|
|
|
|
|
void AppendTreeToInlined(CordRep* tree, MethodIdentifier method);
|
|
|
|
void AppendTreeToTree(CordRep* tree, MethodIdentifier method);
|
|
|
|
void AppendTree(CordRep* tree, MethodIdentifier method);
|
|
|
|
void PrependTreeToInlined(CordRep* tree, MethodIdentifier method);
|
|
|
|
void PrependTreeToTree(CordRep* tree, MethodIdentifier method);
|
|
|
|
void PrependTree(CordRep* tree, MethodIdentifier method);
|
|
|
|
|
|
|
|
template <bool has_length>
|
|
|
|
void GetAppendRegion(char** region, size_t* size, size_t length);
|
|
|
|
|
|
|
|
bool IsSame(const InlineRep& other) const {
|
|
|
|
return memcmp(&data_, &other.data_, sizeof(data_)) == 0;
|
|
|
|
}
|
|
|
|
int BitwiseCompare(const InlineRep& other) const {
|
|
|
|
uint64_t x, y;
|
|
|
|
// Use memcpy to avoid aliasing issues.
|
|
|
|
memcpy(&x, &data_, sizeof(x));
|
|
|
|
memcpy(&y, &other.data_, sizeof(y));
|
|
|
|
if (x == y) {
|
|
|
|
memcpy(&x, reinterpret_cast<const char*>(&data_) + 8, sizeof(x));
|
|
|
|
memcpy(&y, reinterpret_cast<const char*>(&other.data_) + 8, sizeof(y));
|
|
|
|
if (x == y) return 0;
|
|
|
|
}
|
|
|
|
return absl::big_endian::FromHost64(x) < absl::big_endian::FromHost64(y)
|
|
|
|
? -1
|
|
|
|
: 1;
|
|
|
|
}
|
|
|
|
void CopyTo(std::string* dst) const {
|
|
|
|
// memcpy is much faster when operating on a known size. On most supported
|
|
|
|
// platforms, the small string optimization is large enough that resizing
|
|
|
|
// to 15 bytes does not cause a memory allocation.
|
|
|
|
absl::strings_internal::STLStringResizeUninitialized(dst,
|
|
|
|
sizeof(data_) - 1);
|
|
|
|
memcpy(&(*dst)[0], &data_, sizeof(data_) - 1);
|
|
|
|
// erase is faster than resize because the logic for memory allocation is
|
|
|
|
// not needed.
|
|
|
|
dst->erase(inline_size());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copies the inline contents into `dst`. Assumes the cord is not empty.
|
|
|
|
void CopyToArray(char* dst) const;
|
|
|
|
|
|
|
|
bool is_tree() const { return data_.is_tree(); }
|
|
|
|
|
|
|
|
// Returns true if the Cord is being profiled by cordz.
|
|
|
|
bool is_profiled() const { return data_.is_tree() && data_.is_profiled(); }
|
|
|
|
|
|
|
|
// Returns the available inlined capacity, or 0 if is_tree() == true.
|
Export of internal Abseil changes
--
07240ca7822d007cdcc79f2c40bd58b2c2010348 by Abseil Team <absl-team@google.com>:
Correct the comment from "AlphaNum" to "Arg".
PiperOrigin-RevId: 416139192
--
adcba4a6b3763626e1db7b1e8c108b3114903557 by Martijn Vels <mvels@google.com>:
Fix NewExternalRep() to require data being non-empty, and remove nullptr return.
PiperOrigin-RevId: 416135865
--
c0d14cd918fb16f15d1d84de9284b5c5ecc1f8f2 by Abseil Team <absl-team@google.com>:
Fix doc comment for absl::ascii_isprint().
The comment was incorrectly saying that it includes all whitespace.
It doesn't; the only whitespace char it includes is ' '.
PiperOrigin-RevId: 416112524
--
d83327800159c07002b6865e21232a12463e02dd by Abseil Team <absl-team@google.com>:
Internal change
PiperOrigin-RevId: 416099978
--
baf11e9ca42ca9140cdbf8075f971db8d65b1195 by Ilya Tokar <tokarip@google.com>:
Prevent compiler from optimizing Group_Match* benchmarks away.
Currently we benchmark single store of precomputed value.
Not all affected benchmarks show performance changes:
BM_Group_Match 0.53ns ± 1% 0.53ns ± 0% -0.42% (p=0.038 n=10+10)
BM_Group_MatchEmpty 0.26ns ± 1% 0.26ns ± 1% ~ (p=1.000 n=10+10)
BM_Group_MatchEmptyOrDeleted 0.26ns ± 1% 0.26ns ± 1% ~ (p=0.121 n=10+10)
BM_Group_CountLeadingEmptyOrDeleted 0.26ns ± 1% 0.45ns ± 0% +70.05% (p=0.000 n=10+8)
BM_Group_MatchFirstEmptyOrDeleted 0.26ns ± 0% 0.44ns ± 1% +65.91% (p=0.000 n=8+9)
But inspecting the generated code shows the difference,
e. g. BM_Group_MatchFirstEmptyOrDeleted
Before:
add $0xffffffffffffffff,%rbx
jne 30
After:
pcmpeqd %xmm0,%xmm0
pcmpgtb -0x30(%rbp),%xmm0
pmovmskb %xmm0,%eax
add: 0x23$0xffffffffffffffff,%rbx
jne 40
PiperOrigin-RevId: 416083515
--
122fbff893dc4571b3e75e4b241eb4495b925610 by Abseil Team <absl-team@google.com>:
Put namespace guard in ABSL_DECLARE_FLAG to make declaring a flag in a namespace a compiler error instead of a linker error.
PiperOrigin-RevId: 416036072
--
020fd8a20f5fa319e948846e003391fcb9e03868 by Ilya Tokar <tokarip@google.com>:
Make Cord::InlineRep::set_data unconditionally zero out memory.
Currently there is a single case where we don't zero out memory
as an optimization. Unconditional zeroing doesn't show any changes
in benchmarks, except for the unrelated improvement:
BM_CordPartialCopyToCord/1M/1 12.6ns ± 4% 12.6ns ± 4% ~ (p=0.857 n=16+19)
BM_CordPartialCopyToCord/1M/128 44.9ns ± 7% 45.0ns ± 3% ~ (p=0.468 n=18+17)
BM_CordPartialCopyToCord/1M/1k 64.5ns ± 4% 61.4ns ± 4% -4.82% (p=0.000 n=19+17)
BM_CordPartialCopyToCord/1M/8k 139ns ± 3% 128ns ±15% -7.76% (p=0.009 n=17+20)
BM_CordPartialCopyToCord/1M/16k 193ns ± 6% 168ns ± 6% -13.17% (p=0.000 n=17+17)
BM_CordPartialCopyToCord/4M/16k 199ns ± 4% 177ns ± 4% -11.36% (p=0.000 n=17+18)
BM_CordPartialCopyToCord/4M/32k 275ns ± 3% 250ns ± 4% -9.00% (p=0.000 n=18+18)
BM_CordPartialCopyToCord/4M/64k 291ns ± 4% 266ns ± 5% -8.53% (p=0.000 n=18+16)
BM_CordPartialCopyToCord/4M/128k 322ns ± 5% 291ns ± 4% -9.43% (p=0.000 n=20+18)
BM_CordPartialCopyToCord/8M/32k 281ns ± 5% 251ns ± 4% -10.38% (p=0.000 n=20+16)
BM_CordPartialCopyToCord/8M/64k 293ns ± 6% 267ns ± 4% -8.87% (p=0.000 n=16+19)
BM_CordPartialCopyToCord/8M/128k 334ns ± 3% 305ns ± 2% -8.56% (p=0.000 n=17+16)
This is clearly an alignmnet effect since number of the executed instructions is the same:
M_CordPartialCopyToCord/1M/1 155 ± 0% 155 ± 0% ~ (all samples are equal)
BM_CordPartialCopyToCord/1M/128 446 ± 0% 446 ± 0% ~ (p=0.332 n=36+39)
BM_CordPartialCopyToCord/1M/1k 473 ± 0% 473 ± 0% ~ (p=0.969 n=40+40)
BM_CordPartialCopyToCord/1M/8k 808 ± 0% 808 ± 0% ~ (p=0.127 n=40+39)
BM_CordPartialCopyToCord/1M/16k 957 ± 0% 957 ± 0% ~ (p=0.532 n=40+40)
BM_CordPartialCopyToCord/4M/16k 952 ± 0% 952 ± 0% ~ (p=0.686 n=39+39)
BM_CordPartialCopyToCord/4M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.690 n=40+40)
BM_CordPartialCopyToCord/4M/64k 1.23k ± 0% 1.23k ± 0% ~ (p=0.182 n=40+39)
BM_CordPartialCopyToCord/4M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.711 n=40+40)
BM_CordPartialCopyToCord/8M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.697 n=40+40)
BM_CordPartialCopyToCord/8M/64k 1.23k ± 0% 1.23k ± 0% +0.00% (p=0.049 n=40+40)
BM_CordPartialCopyToCord/8M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.507 n=40+40)
This makes code simpler and doesn't regress performance.
PiperOrigin-RevId: 415560574
--
37305b2690b31682088749e4d62f40d7095bdc54 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 415558737
--
86aaed569b9e743c1eb813a5f48def978a793db3 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415515201
--
6cdb8786cdcb4fa0b8a4b72fc98940877d1fdeff by Abseil Team <absl-team@google.com>:
Update SubmitMutexProfileData to accept wait_cycles instead of wait_timestamp
PiperOrigin-RevId: 415360871
--
9f979d307aa16ad09f214e04876cbe84395c0901 by Abseil Team <absl-team@google.com>:
absl::flat_hash_set compiles with -Wconversion -Wsign-compare
PiperOrigin-RevId: 415357498
--
9eceb14174708f15e61259d449b214a8a4c7f9e7 by Abseil Team <absl-team@google.com>:
Fix AddressIsReadable for the corner case of (aligned) addr == NULL.
PiperOrigin-RevId: 415307792
--
1a39ffe55898375e2d7f88c17c99db5a1b95b313 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415162872
--
64378549b110d5f5762185a5906c520fba70f0e7 by Abseil Team <absl-team@google.com>:
Fix a typo in the comments
PiperOrigin-RevId: 415088461
--
41aae8322e913b82710153c22b97c611fdb6e1fb by Abseil Team <absl-team@google.com>:
Switch from `connect` to `rt_sigreturn` -- the latter is much less problematic
for system call sandboxes.
PiperOrigin-RevId: 415073965
--
870c5e3388b6a35611bff538626fe7a1c8c87171 by Abseil Team <absl-team@google.com>:
Add ABSL_HAVE_HWADDRESS_SANITIZER and ABSL_HAVE_LEAK_SANITIZER
PiperOrigin-RevId: 414871189
--
f213ed60a66b58da7ac40555adfb1d529ff0a4db by Derek Mauro <dmauro@google.com>:
Remove reference to __SANITIZE_MEMORY__, which does not exist
It appears to have been copied by pattern matching from the ASAN/TSAN
code blocks.
https://github.com/gcc-mirror/gcc/blob/f47662204de27f7685699eeef89aa173ccf32d85/gcc/cppbuiltin.c#L79-L126
PiperOrigin-RevId: 414806587
--
b152891e73ab515f397ceb53f66c8ee2f33863ea by Abseil Team <absl-team@google.com>:
Rollback previous commit: SYS_open is not defined in certain environments.
PiperOrigin-RevId: 414521820
--
5a1cbb282331023902e1374dd0d920c4effbe47f by Abseil Team <absl-team@google.com>:
Use syscall(SYS_open, ...) instead of open() to avoid possible symbol
interposition.
Also add some warning notes.
PiperOrigin-RevId: 414508186
--
1824d6593612710aafdc599a89b0adced7d787f6 by Abseil Team <absl-team@google.com>:
Correct aarch64 macro check
The macro is __aarch64__, not __arch64__.
PiperOrigin-RevId: 414446225
--
a1536a57b64dfd53945d33a01cfc08b18c99c97b by Abseil Team <absl-team@google.com>:
Fix backwards comment in the last commit.
PiperOrigin-RevId: 414281214
--
11ac021ba779513667a31cf2563ddafc57d6d913 by Abseil Team <absl-team@google.com>:
AddressIsReadable() didn't work correctly on ARM when the given pointer was
misaligned at the end of the page.
Fix that by aligning the pointer on an 8-byte boundary before checking it.
PiperOrigin-RevId: 414203863
GitOrigin-RevId: 07240ca7822d007cdcc79f2c40bd58b2c2010348
Change-Id: If5f129194d59f5c9e5d84efd8cd9e17a70e072ab
3 years ago
|
|
|
size_t remaining_inline_capacity() const {
|
|
|
|
return data_.is_tree() ? 0 : kMaxInline - data_.inline_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the profiled CordzInfo, or nullptr if not sampled.
|
|
|
|
absl::cord_internal::CordzInfo* cordz_info() const {
|
|
|
|
return data_.cordz_info();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets the profiled CordzInfo. `cordz_info` must not be null.
|
|
|
|
void set_cordz_info(cord_internal::CordzInfo* cordz_info) {
|
|
|
|
assert(cordz_info != nullptr);
|
|
|
|
data_.set_cordz_info(cordz_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resets the current cordz_info to null / empty.
|
|
|
|
void clear_cordz_info() { data_.clear_cordz_info(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class Cord;
|
|
|
|
|
|
|
|
void AssignSlow(const InlineRep& src);
|
|
|
|
// Unrefs the tree and stops profiling.
|
|
|
|
void UnrefTree();
|
|
|
|
|
|
|
|
void ResetToEmpty() { data_ = {}; }
|
|
|
|
|
|
|
|
void set_inline_size(size_t size) { data_.set_inline_size(size); }
|
|
|
|
size_t inline_size() const { return data_.inline_size(); }
|
|
|
|
|
|
|
|
cord_internal::InlineData data_;
|
|
|
|
};
|
|
|
|
InlineRep contents_;
|
|
|
|
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// Helper for GetFlat() and TryFlat().
|
|
|
|
static bool GetFlatAux(absl::cord_internal::CordRep* rep,
|
|
|
|
absl::string_view* fragment);
|
|
|
|
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// Helper for ForEachChunk().
|
|
|
|
static void ForEachChunkAux(
|
|
|
|
absl::cord_internal::CordRep* rep,
|
|
|
|
absl::FunctionRef<void(absl::string_view)> callback);
|
|
|
|
|
|
|
|
// The destructor for non-empty Cords.
|
|
|
|
void DestroyCordSlow();
|
|
|
|
|
|
|
|
// Out-of-line implementation of slower parts of logic.
|
|
|
|
void CopyToArraySlowPath(char* dst) const;
|
|
|
|
int CompareSlowPath(absl::string_view rhs, size_t compared_size,
|
|
|
|
size_t size_to_compare) const;
|
|
|
|
int CompareSlowPath(const Cord& rhs, size_t compared_size,
|
|
|
|
size_t size_to_compare) const;
|
|
|
|
bool EqualsImpl(absl::string_view rhs, size_t size_to_compare) const;
|
|
|
|
bool EqualsImpl(const Cord& rhs, size_t size_to_compare) const;
|
|
|
|
int CompareImpl(const Cord& rhs) const;
|
|
|
|
|
|
|
|
template <typename ResultType, typename RHS>
|
|
|
|
friend ResultType GenericCompare(const Cord& lhs, const RHS& rhs,
|
|
|
|
size_t size_to_compare);
|
|
|
|
static absl::string_view GetFirstChunk(const Cord& c);
|
|
|
|
static absl::string_view GetFirstChunk(absl::string_view sv);
|
|
|
|
|
|
|
|
// Returns a new reference to contents_.tree(), or steals an existing
|
|
|
|
// reference if called on an rvalue.
|
|
|
|
absl::cord_internal::CordRep* TakeRep() const&;
|
|
|
|
absl::cord_internal::CordRep* TakeRep() &&;
|
|
|
|
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// Helper for Append().
|
|
|
|
template <typename C>
|
|
|
|
void AppendImpl(C&& src);
|
|
|
|
|
Export of internal Abseil changes
--
f49e405201d2ffd5955503fa8ad0f08ec0cdfb2b by Martijn Vels <mvels@google.com>:
Add common [container.requirements] type definitions to `CharRange` and `ChunkRange`
The presence of these allow these range classes to be used in various utility functions which require some minimum type of container. For example, this change allows tests to use `EXPECT_THAT(cord.Chunks(), ElementsAre(...))`
PiperOrigin-RevId: 406941278
--
0c195f073632e21d9a4bce158047b2ba8551c2d1 by Evan Brown <ezb@google.com>:
Use explicit exponential growth in SubstituteAndAppendArray.
PiperOrigin-RevId: 406931952
--
afb043bccd809a55cab78abadb7548a057d9eda0 by Jorg Brown <jorg@google.com>:
Use longer var names in macro to avoid clang-tidy warning
PiperOrigin-RevId: 406930978
--
80397e2604e6b3d929a34742c3a32581b34d3ac4 by Martijn Vels <mvels@google.com>:
Add future kAppendBuffer and kPrependBuffer API trackers for Cordz sampling
PiperOrigin-RevId: 406912759
--
e910ce919ef83933f08a690e8b7325c7cc5b6d5d by Martijn Vels <mvels@google.com>:
Implement Prepend(string_view) in terms of PrependArray(string_view, MethodIdentifier).
PiperOrigin-RevId: 406891665
--
c9cff43d4c0568ed01f2fca0f6ef038ae03112b5 by Martijn Vels <mvels@google.com>:
Add 'Rebuild' logic to CordRepBtree
There are btree hostile scenarios where an application could perform repeated split/insert/merge operations on a cord leading to a tree exceeding the maximum height. While this should be rare in practice, this change adds a Rebuild() method that will rebuild a tree with a 100% fill factor, and we will invoke this rebuild when a tree exceeds the maximum height. This basically follows the similar 'balance' logic in Concat trees (although the latter is common in Concat uses)
PiperOrigin-RevId: 406875739
--
5b2b8fb88f1ebfdc1c670088152da2cb2ea4c376 by Martijn Vels <mvels@google.com>:
Add 'in place' enabled RemoveSuffix
An in-place RemoveSuffix is more efficient than SubTree() as it can directly modify privately owned nodes and flats allowing easy re-use of free capacity in right-most flats that may turn into Substring edges when using SubTree.
PiperOrigin-RevId: 406431230
--
f09903c0a3d7344f59aaf1380a16ea10829217d4 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 406430373
--
9957af575c33bb18dc170572a4ee8cc5901df6b2 by Greg Falcon <gfalcon@google.com>:
Initial groundwork to allow storing checksum data inside CordRep instances.
This uses a RefcountAndFlags bit that was reserved for this purpose, and will be leveraged in a follow-up change to allow attaching checksums to a Cord's value.
This change splits RefcountAndFlags::IsOne() into two distinct operations:
* IsOne(): This returns true when the associated CordRep is not shared with other threads. This is useful for functions that consume CordRep instances; for example, code that consumes an unshared CordRep can assume ownership of its children without modifying those refcounts.
* IsMutable(): This returns true when the associated CordRep reference is not shared with other threads, *and* does not store an associated checksum value. This is useful for functions that modify a CordRep's contents: code may modify the bytes of a mutable-unshared CordRep without fear of races with other threads, or of invalidating a stored checksum.
The tricky part of this CL is ensuring that the correct choice between IsMutable() and IsOne() was made at each point. An incorrect application of IsOne() could lead to correctness bugs in the future. Code conditioned on IsOne() may delete the CordRep in question, or assume ownership of its children, but must not modify the CordRep's data without explicitly adjusting the CRC.
PiperOrigin-RevId: 406191103
--
686544814079e5ab6d4593cca0c068b510be400a by Martijn Vels <mvels@google.com>:
Reduce the size in the LargeString test when running with Sanitizers
PiperOrigin-RevId: 406186945
--
735b4490bdb695c35731f06ce4b8de14ce2be6ed by Alex Strelnikov <strel@google.com>:
Release absl::SimpleHexAtoi.
PiperOrigin-RevId: 406143188
GitOrigin-RevId: f49e405201d2ffd5955503fa8ad0f08ec0cdfb2b
Change-Id: Ic6527ac40fa03ea02ca813e8bb7868a219544de4
3 years ago
|
|
|
// Prepends the provided data to this instance. `method` contains the public
|
|
|
|
// API method for this action which is tracked for Cordz sampling purposes.
|
|
|
|
void PrependArray(absl::string_view src, MethodIdentifier method);
|
|
|
|
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
// Assigns the value in 'src' to this instance, 'stealing' its contents.
|
|
|
|
// Requires src.length() > kMaxBytesToCopy.
|
|
|
|
Cord& AssignLargeString(std::string&& src);
|
|
|
|
|
Export of internal Abseil changes
--
790f9061df340cd900e8da70e66c363f7af3c2eb by Abseil Team <absl-team@google.com>:
Add support for rvalue reference to function types.
PiperOrigin-RevId: 324508531
--
51fe201dbb41a3ebc3d49ff65250b5f464279d43 by Abseil Team <absl-team@google.com>:
Cleaning up function comment style; no substantive change.
PiperOrigin-RevId: 324497401
--
da8595d5266577d0c170528d12f6de17b8affcc2 by Abseil Team <absl-team@google.com>:
Add support for demangling GNU vector types.
PiperOrigin-RevId: 324494559
--
0cb0acf88c1750f6963c9cb85249f9b4f0bd5104 by Abseil Team <absl-team@google.com>:
Add support for thread-local types.
PiperOrigin-RevId: 324491183
--
c676bc8380560599cd26f7f231e04e6be532e904 by Abseil Team <absl-team@google.com>:
Add support for demangling "Du" (char8_t).
PiperOrigin-RevId: 324441607
--
b218bf6467bc62b327214782c881e8224ad91509 by Abseil Team <absl-team@google.com>:
Update doc comments in header of `any.h` to reflect that `absl::variant` has been released.
PiperOrigin-RevId: 324431690
--
e5b579f3f1aa598c1f62e71dba7103b98811de59 by Laramie Leavitt <lar@google.com>:
Bugfix: Fix bounds in absl::Uniform where one of the bounds is min/max.
When absl::Uniform(rng, tag, a, b) is called, the tag is used in conjunction with the type to determine whether or not to manipulate the bounds to make them inclusive or exclusive through the uniform_*_bound functions. Unfortunately, at limits of the interval the function was not well behaved.
The previous implementation used wrapping arithmetic. This causes incorrect bounds computation at the extremes (numeric_limits::min / numeric_limits::max) the bound would wrap.
Improve this situation by:
1/ Changing the uniform_*_bound functions to use saturating arithmetic instead of wrapping, thus in the unsigned case, the upper_bound of IntervalOpenOpen for 0 is now 0, rather than numeric_limits::max, likewise for the lower bound.
2/ Adjusting the hi/lo checks in the distributions. When the interval is empty, such as for absl::Uniform(absl::IntervalOpenOpen, gen, 1, 0), the return value is somewhat nonsensical. Now absl::Uniform more consistently returns the low input rather than any adjusted input. In the above case, that means that 1 is returned rather than 2.
NOTE: Calls to absl::Uniform where the resolved upper bound is < the lower bound are still ill-formed and should be avoided.
3/ Adding better tests.
The underlying uniform_*_distribution classes are not affected.
PiperOrigin-RevId: 324240873
GitOrigin-RevId: 790f9061df340cd900e8da70e66c363f7af3c2eb
Change-Id: I2a2208650ea3135c575e200b868ce1d275069fc8
4 years ago
|
|
|
// Helper for AbslHashValue().
|
|
|
|
template <typename H>
|
|
|
|
H HashFragmented(H hash_state) const {
|
|
|
|
typename H::AbslInternalPiecewiseCombiner combiner;
|
|
|
|
ForEachChunk([&combiner, &hash_state](absl::string_view chunk) {
|
|
|
|
hash_state = combiner.add_buffer(std::move(hash_state), chunk.data(),
|
|
|
|
chunk.size());
|
|
|
|
});
|
|
|
|
return H::combine(combiner.finalize(std::move(hash_state)), size());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ABSL_NAMESPACE_END
|
|
|
|
} // namespace absl
|
|
|
|
|
|
|
|
namespace absl {
|
|
|
|
ABSL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
// allow a Cord to be logged
|
|
|
|
extern std::ostream& operator<<(std::ostream& out, const Cord& cord);
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
|
|
// Internal details follow. Clients should ignore.
|
|
|
|
|
|
|
|
namespace cord_internal {
|
|
|
|
|
|
|
|
// Fast implementation of memmove for up to 15 bytes. This implementation is
|
|
|
|
// safe for overlapping regions. If nullify_tail is true, the destination is
|
|
|
|
// padded with '\0' up to 16 bytes.
|
Export of internal Abseil changes
--
07240ca7822d007cdcc79f2c40bd58b2c2010348 by Abseil Team <absl-team@google.com>:
Correct the comment from "AlphaNum" to "Arg".
PiperOrigin-RevId: 416139192
--
adcba4a6b3763626e1db7b1e8c108b3114903557 by Martijn Vels <mvels@google.com>:
Fix NewExternalRep() to require data being non-empty, and remove nullptr return.
PiperOrigin-RevId: 416135865
--
c0d14cd918fb16f15d1d84de9284b5c5ecc1f8f2 by Abseil Team <absl-team@google.com>:
Fix doc comment for absl::ascii_isprint().
The comment was incorrectly saying that it includes all whitespace.
It doesn't; the only whitespace char it includes is ' '.
PiperOrigin-RevId: 416112524
--
d83327800159c07002b6865e21232a12463e02dd by Abseil Team <absl-team@google.com>:
Internal change
PiperOrigin-RevId: 416099978
--
baf11e9ca42ca9140cdbf8075f971db8d65b1195 by Ilya Tokar <tokarip@google.com>:
Prevent compiler from optimizing Group_Match* benchmarks away.
Currently we benchmark single store of precomputed value.
Not all affected benchmarks show performance changes:
BM_Group_Match 0.53ns ± 1% 0.53ns ± 0% -0.42% (p=0.038 n=10+10)
BM_Group_MatchEmpty 0.26ns ± 1% 0.26ns ± 1% ~ (p=1.000 n=10+10)
BM_Group_MatchEmptyOrDeleted 0.26ns ± 1% 0.26ns ± 1% ~ (p=0.121 n=10+10)
BM_Group_CountLeadingEmptyOrDeleted 0.26ns ± 1% 0.45ns ± 0% +70.05% (p=0.000 n=10+8)
BM_Group_MatchFirstEmptyOrDeleted 0.26ns ± 0% 0.44ns ± 1% +65.91% (p=0.000 n=8+9)
But inspecting the generated code shows the difference,
e. g. BM_Group_MatchFirstEmptyOrDeleted
Before:
add $0xffffffffffffffff,%rbx
jne 30
After:
pcmpeqd %xmm0,%xmm0
pcmpgtb -0x30(%rbp),%xmm0
pmovmskb %xmm0,%eax
add: 0x23$0xffffffffffffffff,%rbx
jne 40
PiperOrigin-RevId: 416083515
--
122fbff893dc4571b3e75e4b241eb4495b925610 by Abseil Team <absl-team@google.com>:
Put namespace guard in ABSL_DECLARE_FLAG to make declaring a flag in a namespace a compiler error instead of a linker error.
PiperOrigin-RevId: 416036072
--
020fd8a20f5fa319e948846e003391fcb9e03868 by Ilya Tokar <tokarip@google.com>:
Make Cord::InlineRep::set_data unconditionally zero out memory.
Currently there is a single case where we don't zero out memory
as an optimization. Unconditional zeroing doesn't show any changes
in benchmarks, except for the unrelated improvement:
BM_CordPartialCopyToCord/1M/1 12.6ns ± 4% 12.6ns ± 4% ~ (p=0.857 n=16+19)
BM_CordPartialCopyToCord/1M/128 44.9ns ± 7% 45.0ns ± 3% ~ (p=0.468 n=18+17)
BM_CordPartialCopyToCord/1M/1k 64.5ns ± 4% 61.4ns ± 4% -4.82% (p=0.000 n=19+17)
BM_CordPartialCopyToCord/1M/8k 139ns ± 3% 128ns ±15% -7.76% (p=0.009 n=17+20)
BM_CordPartialCopyToCord/1M/16k 193ns ± 6% 168ns ± 6% -13.17% (p=0.000 n=17+17)
BM_CordPartialCopyToCord/4M/16k 199ns ± 4% 177ns ± 4% -11.36% (p=0.000 n=17+18)
BM_CordPartialCopyToCord/4M/32k 275ns ± 3% 250ns ± 4% -9.00% (p=0.000 n=18+18)
BM_CordPartialCopyToCord/4M/64k 291ns ± 4% 266ns ± 5% -8.53% (p=0.000 n=18+16)
BM_CordPartialCopyToCord/4M/128k 322ns ± 5% 291ns ± 4% -9.43% (p=0.000 n=20+18)
BM_CordPartialCopyToCord/8M/32k 281ns ± 5% 251ns ± 4% -10.38% (p=0.000 n=20+16)
BM_CordPartialCopyToCord/8M/64k 293ns ± 6% 267ns ± 4% -8.87% (p=0.000 n=16+19)
BM_CordPartialCopyToCord/8M/128k 334ns ± 3% 305ns ± 2% -8.56% (p=0.000 n=17+16)
This is clearly an alignmnet effect since number of the executed instructions is the same:
M_CordPartialCopyToCord/1M/1 155 ± 0% 155 ± 0% ~ (all samples are equal)
BM_CordPartialCopyToCord/1M/128 446 ± 0% 446 ± 0% ~ (p=0.332 n=36+39)
BM_CordPartialCopyToCord/1M/1k 473 ± 0% 473 ± 0% ~ (p=0.969 n=40+40)
BM_CordPartialCopyToCord/1M/8k 808 ± 0% 808 ± 0% ~ (p=0.127 n=40+39)
BM_CordPartialCopyToCord/1M/16k 957 ± 0% 957 ± 0% ~ (p=0.532 n=40+40)
BM_CordPartialCopyToCord/4M/16k 952 ± 0% 952 ± 0% ~ (p=0.686 n=39+39)
BM_CordPartialCopyToCord/4M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.690 n=40+40)
BM_CordPartialCopyToCord/4M/64k 1.23k ± 0% 1.23k ± 0% ~ (p=0.182 n=40+39)
BM_CordPartialCopyToCord/4M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.711 n=40+40)
BM_CordPartialCopyToCord/8M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.697 n=40+40)
BM_CordPartialCopyToCord/8M/64k 1.23k ± 0% 1.23k ± 0% +0.00% (p=0.049 n=40+40)
BM_CordPartialCopyToCord/8M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.507 n=40+40)
This makes code simpler and doesn't regress performance.
PiperOrigin-RevId: 415560574
--
37305b2690b31682088749e4d62f40d7095bdc54 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 415558737
--
86aaed569b9e743c1eb813a5f48def978a793db3 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415515201
--
6cdb8786cdcb4fa0b8a4b72fc98940877d1fdeff by Abseil Team <absl-team@google.com>:
Update SubmitMutexProfileData to accept wait_cycles instead of wait_timestamp
PiperOrigin-RevId: 415360871
--
9f979d307aa16ad09f214e04876cbe84395c0901 by Abseil Team <absl-team@google.com>:
absl::flat_hash_set compiles with -Wconversion -Wsign-compare
PiperOrigin-RevId: 415357498
--
9eceb14174708f15e61259d449b214a8a4c7f9e7 by Abseil Team <absl-team@google.com>:
Fix AddressIsReadable for the corner case of (aligned) addr == NULL.
PiperOrigin-RevId: 415307792
--
1a39ffe55898375e2d7f88c17c99db5a1b95b313 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415162872
--
64378549b110d5f5762185a5906c520fba70f0e7 by Abseil Team <absl-team@google.com>:
Fix a typo in the comments
PiperOrigin-RevId: 415088461
--
41aae8322e913b82710153c22b97c611fdb6e1fb by Abseil Team <absl-team@google.com>:
Switch from `connect` to `rt_sigreturn` -- the latter is much less problematic
for system call sandboxes.
PiperOrigin-RevId: 415073965
--
870c5e3388b6a35611bff538626fe7a1c8c87171 by Abseil Team <absl-team@google.com>:
Add ABSL_HAVE_HWADDRESS_SANITIZER and ABSL_HAVE_LEAK_SANITIZER
PiperOrigin-RevId: 414871189
--
f213ed60a66b58da7ac40555adfb1d529ff0a4db by Derek Mauro <dmauro@google.com>:
Remove reference to __SANITIZE_MEMORY__, which does not exist
It appears to have been copied by pattern matching from the ASAN/TSAN
code blocks.
https://github.com/gcc-mirror/gcc/blob/f47662204de27f7685699eeef89aa173ccf32d85/gcc/cppbuiltin.c#L79-L126
PiperOrigin-RevId: 414806587
--
b152891e73ab515f397ceb53f66c8ee2f33863ea by Abseil Team <absl-team@google.com>:
Rollback previous commit: SYS_open is not defined in certain environments.
PiperOrigin-RevId: 414521820
--
5a1cbb282331023902e1374dd0d920c4effbe47f by Abseil Team <absl-team@google.com>:
Use syscall(SYS_open, ...) instead of open() to avoid possible symbol
interposition.
Also add some warning notes.
PiperOrigin-RevId: 414508186
--
1824d6593612710aafdc599a89b0adced7d787f6 by Abseil Team <absl-team@google.com>:
Correct aarch64 macro check
The macro is __aarch64__, not __arch64__.
PiperOrigin-RevId: 414446225
--
a1536a57b64dfd53945d33a01cfc08b18c99c97b by Abseil Team <absl-team@google.com>:
Fix backwards comment in the last commit.
PiperOrigin-RevId: 414281214
--
11ac021ba779513667a31cf2563ddafc57d6d913 by Abseil Team <absl-team@google.com>:
AddressIsReadable() didn't work correctly on ARM when the given pointer was
misaligned at the end of the page.
Fix that by aligning the pointer on an 8-byte boundary before checking it.
PiperOrigin-RevId: 414203863
GitOrigin-RevId: 07240ca7822d007cdcc79f2c40bd58b2c2010348
Change-Id: If5f129194d59f5c9e5d84efd8cd9e17a70e072ab
3 years ago
|
|
|
template <bool nullify_tail = false>
|
|
|
|
inline void SmallMemmove(char* dst, const char* src, size_t n) {
|
|
|
|
if (n >= 8) {
|
|
|
|
assert(n <= 16);
|
|
|
|
uint64_t buf1;
|
|
|
|
uint64_t buf2;
|
|
|
|
memcpy(&buf1, src, 8);
|
|
|
|
memcpy(&buf2, src + n - 8, 8);
|
|
|
|
if (nullify_tail) {
|
|
|
|
memset(dst + 8, 0, 8);
|
|
|
|
}
|
|
|
|
memcpy(dst, &buf1, 8);
|
|
|
|
memcpy(dst + n - 8, &buf2, 8);
|
|
|
|
} else if (n >= 4) {
|
|
|
|
uint32_t buf1;
|
|
|
|
uint32_t buf2;
|
|
|
|
memcpy(&buf1, src, 4);
|
|
|
|
memcpy(&buf2, src + n - 4, 4);
|
|
|
|
if (nullify_tail) {
|
|
|
|
memset(dst + 4, 0, 4);
|
|
|
|
memset(dst + 8, 0, 8);
|
|
|
|
}
|
|
|
|
memcpy(dst, &buf1, 4);
|
|
|
|
memcpy(dst + n - 4, &buf2, 4);
|
|
|
|
} else {
|
|
|
|
if (n != 0) {
|
|
|
|
dst[0] = src[0];
|
|
|
|
dst[n / 2] = src[n / 2];
|
|
|
|
dst[n - 1] = src[n - 1];
|
|
|
|
}
|
|
|
|
if (nullify_tail) {
|
|
|
|
memset(dst + 8, 0, 8);
|
|
|
|
memset(dst + n, 0, 8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Does non-template-specific `CordRepExternal` initialization.
|
Export of internal Abseil changes
--
07240ca7822d007cdcc79f2c40bd58b2c2010348 by Abseil Team <absl-team@google.com>:
Correct the comment from "AlphaNum" to "Arg".
PiperOrigin-RevId: 416139192
--
adcba4a6b3763626e1db7b1e8c108b3114903557 by Martijn Vels <mvels@google.com>:
Fix NewExternalRep() to require data being non-empty, and remove nullptr return.
PiperOrigin-RevId: 416135865
--
c0d14cd918fb16f15d1d84de9284b5c5ecc1f8f2 by Abseil Team <absl-team@google.com>:
Fix doc comment for absl::ascii_isprint().
The comment was incorrectly saying that it includes all whitespace.
It doesn't; the only whitespace char it includes is ' '.
PiperOrigin-RevId: 416112524
--
d83327800159c07002b6865e21232a12463e02dd by Abseil Team <absl-team@google.com>:
Internal change
PiperOrigin-RevId: 416099978
--
baf11e9ca42ca9140cdbf8075f971db8d65b1195 by Ilya Tokar <tokarip@google.com>:
Prevent compiler from optimizing Group_Match* benchmarks away.
Currently we benchmark single store of precomputed value.
Not all affected benchmarks show performance changes:
BM_Group_Match 0.53ns ± 1% 0.53ns ± 0% -0.42% (p=0.038 n=10+10)
BM_Group_MatchEmpty 0.26ns ± 1% 0.26ns ± 1% ~ (p=1.000 n=10+10)
BM_Group_MatchEmptyOrDeleted 0.26ns ± 1% 0.26ns ± 1% ~ (p=0.121 n=10+10)
BM_Group_CountLeadingEmptyOrDeleted 0.26ns ± 1% 0.45ns ± 0% +70.05% (p=0.000 n=10+8)
BM_Group_MatchFirstEmptyOrDeleted 0.26ns ± 0% 0.44ns ± 1% +65.91% (p=0.000 n=8+9)
But inspecting the generated code shows the difference,
e. g. BM_Group_MatchFirstEmptyOrDeleted
Before:
add $0xffffffffffffffff,%rbx
jne 30
After:
pcmpeqd %xmm0,%xmm0
pcmpgtb -0x30(%rbp),%xmm0
pmovmskb %xmm0,%eax
add: 0x23$0xffffffffffffffff,%rbx
jne 40
PiperOrigin-RevId: 416083515
--
122fbff893dc4571b3e75e4b241eb4495b925610 by Abseil Team <absl-team@google.com>:
Put namespace guard in ABSL_DECLARE_FLAG to make declaring a flag in a namespace a compiler error instead of a linker error.
PiperOrigin-RevId: 416036072
--
020fd8a20f5fa319e948846e003391fcb9e03868 by Ilya Tokar <tokarip@google.com>:
Make Cord::InlineRep::set_data unconditionally zero out memory.
Currently there is a single case where we don't zero out memory
as an optimization. Unconditional zeroing doesn't show any changes
in benchmarks, except for the unrelated improvement:
BM_CordPartialCopyToCord/1M/1 12.6ns ± 4% 12.6ns ± 4% ~ (p=0.857 n=16+19)
BM_CordPartialCopyToCord/1M/128 44.9ns ± 7% 45.0ns ± 3% ~ (p=0.468 n=18+17)
BM_CordPartialCopyToCord/1M/1k 64.5ns ± 4% 61.4ns ± 4% -4.82% (p=0.000 n=19+17)
BM_CordPartialCopyToCord/1M/8k 139ns ± 3% 128ns ±15% -7.76% (p=0.009 n=17+20)
BM_CordPartialCopyToCord/1M/16k 193ns ± 6% 168ns ± 6% -13.17% (p=0.000 n=17+17)
BM_CordPartialCopyToCord/4M/16k 199ns ± 4% 177ns ± 4% -11.36% (p=0.000 n=17+18)
BM_CordPartialCopyToCord/4M/32k 275ns ± 3% 250ns ± 4% -9.00% (p=0.000 n=18+18)
BM_CordPartialCopyToCord/4M/64k 291ns ± 4% 266ns ± 5% -8.53% (p=0.000 n=18+16)
BM_CordPartialCopyToCord/4M/128k 322ns ± 5% 291ns ± 4% -9.43% (p=0.000 n=20+18)
BM_CordPartialCopyToCord/8M/32k 281ns ± 5% 251ns ± 4% -10.38% (p=0.000 n=20+16)
BM_CordPartialCopyToCord/8M/64k 293ns ± 6% 267ns ± 4% -8.87% (p=0.000 n=16+19)
BM_CordPartialCopyToCord/8M/128k 334ns ± 3% 305ns ± 2% -8.56% (p=0.000 n=17+16)
This is clearly an alignmnet effect since number of the executed instructions is the same:
M_CordPartialCopyToCord/1M/1 155 ± 0% 155 ± 0% ~ (all samples are equal)
BM_CordPartialCopyToCord/1M/128 446 ± 0% 446 ± 0% ~ (p=0.332 n=36+39)
BM_CordPartialCopyToCord/1M/1k 473 ± 0% 473 ± 0% ~ (p=0.969 n=40+40)
BM_CordPartialCopyToCord/1M/8k 808 ± 0% 808 ± 0% ~ (p=0.127 n=40+39)
BM_CordPartialCopyToCord/1M/16k 957 ± 0% 957 ± 0% ~ (p=0.532 n=40+40)
BM_CordPartialCopyToCord/4M/16k 952 ± 0% 952 ± 0% ~ (p=0.686 n=39+39)
BM_CordPartialCopyToCord/4M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.690 n=40+40)
BM_CordPartialCopyToCord/4M/64k 1.23k ± 0% 1.23k ± 0% ~ (p=0.182 n=40+39)
BM_CordPartialCopyToCord/4M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.711 n=40+40)
BM_CordPartialCopyToCord/8M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.697 n=40+40)
BM_CordPartialCopyToCord/8M/64k 1.23k ± 0% 1.23k ± 0% +0.00% (p=0.049 n=40+40)
BM_CordPartialCopyToCord/8M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.507 n=40+40)
This makes code simpler and doesn't regress performance.
PiperOrigin-RevId: 415560574
--
37305b2690b31682088749e4d62f40d7095bdc54 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 415558737
--
86aaed569b9e743c1eb813a5f48def978a793db3 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415515201
--
6cdb8786cdcb4fa0b8a4b72fc98940877d1fdeff by Abseil Team <absl-team@google.com>:
Update SubmitMutexProfileData to accept wait_cycles instead of wait_timestamp
PiperOrigin-RevId: 415360871
--
9f979d307aa16ad09f214e04876cbe84395c0901 by Abseil Team <absl-team@google.com>:
absl::flat_hash_set compiles with -Wconversion -Wsign-compare
PiperOrigin-RevId: 415357498
--
9eceb14174708f15e61259d449b214a8a4c7f9e7 by Abseil Team <absl-team@google.com>:
Fix AddressIsReadable for the corner case of (aligned) addr == NULL.
PiperOrigin-RevId: 415307792
--
1a39ffe55898375e2d7f88c17c99db5a1b95b313 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415162872
--
64378549b110d5f5762185a5906c520fba70f0e7 by Abseil Team <absl-team@google.com>:
Fix a typo in the comments
PiperOrigin-RevId: 415088461
--
41aae8322e913b82710153c22b97c611fdb6e1fb by Abseil Team <absl-team@google.com>:
Switch from `connect` to `rt_sigreturn` -- the latter is much less problematic
for system call sandboxes.
PiperOrigin-RevId: 415073965
--
870c5e3388b6a35611bff538626fe7a1c8c87171 by Abseil Team <absl-team@google.com>:
Add ABSL_HAVE_HWADDRESS_SANITIZER and ABSL_HAVE_LEAK_SANITIZER
PiperOrigin-RevId: 414871189
--
f213ed60a66b58da7ac40555adfb1d529ff0a4db by Derek Mauro <dmauro@google.com>:
Remove reference to __SANITIZE_MEMORY__, which does not exist
It appears to have been copied by pattern matching from the ASAN/TSAN
code blocks.
https://github.com/gcc-mirror/gcc/blob/f47662204de27f7685699eeef89aa173ccf32d85/gcc/cppbuiltin.c#L79-L126
PiperOrigin-RevId: 414806587
--
b152891e73ab515f397ceb53f66c8ee2f33863ea by Abseil Team <absl-team@google.com>:
Rollback previous commit: SYS_open is not defined in certain environments.
PiperOrigin-RevId: 414521820
--
5a1cbb282331023902e1374dd0d920c4effbe47f by Abseil Team <absl-team@google.com>:
Use syscall(SYS_open, ...) instead of open() to avoid possible symbol
interposition.
Also add some warning notes.
PiperOrigin-RevId: 414508186
--
1824d6593612710aafdc599a89b0adced7d787f6 by Abseil Team <absl-team@google.com>:
Correct aarch64 macro check
The macro is __aarch64__, not __arch64__.
PiperOrigin-RevId: 414446225
--
a1536a57b64dfd53945d33a01cfc08b18c99c97b by Abseil Team <absl-team@google.com>:
Fix backwards comment in the last commit.
PiperOrigin-RevId: 414281214
--
11ac021ba779513667a31cf2563ddafc57d6d913 by Abseil Team <absl-team@google.com>:
AddressIsReadable() didn't work correctly on ARM when the given pointer was
misaligned at the end of the page.
Fix that by aligning the pointer on an 8-byte boundary before checking it.
PiperOrigin-RevId: 414203863
GitOrigin-RevId: 07240ca7822d007cdcc79f2c40bd58b2c2010348
Change-Id: If5f129194d59f5c9e5d84efd8cd9e17a70e072ab
3 years ago
|
|
|
// Requires `data` to be non-empty.
|
|
|
|
void InitializeCordRepExternal(absl::string_view data, CordRepExternal* rep);
|
|
|
|
|
|
|
|
// Creates a new `CordRep` that owns `data` and `releaser` and returns a pointer
|
Export of internal Abseil changes
--
07240ca7822d007cdcc79f2c40bd58b2c2010348 by Abseil Team <absl-team@google.com>:
Correct the comment from "AlphaNum" to "Arg".
PiperOrigin-RevId: 416139192
--
adcba4a6b3763626e1db7b1e8c108b3114903557 by Martijn Vels <mvels@google.com>:
Fix NewExternalRep() to require data being non-empty, and remove nullptr return.
PiperOrigin-RevId: 416135865
--
c0d14cd918fb16f15d1d84de9284b5c5ecc1f8f2 by Abseil Team <absl-team@google.com>:
Fix doc comment for absl::ascii_isprint().
The comment was incorrectly saying that it includes all whitespace.
It doesn't; the only whitespace char it includes is ' '.
PiperOrigin-RevId: 416112524
--
d83327800159c07002b6865e21232a12463e02dd by Abseil Team <absl-team@google.com>:
Internal change
PiperOrigin-RevId: 416099978
--
baf11e9ca42ca9140cdbf8075f971db8d65b1195 by Ilya Tokar <tokarip@google.com>:
Prevent compiler from optimizing Group_Match* benchmarks away.
Currently we benchmark single store of precomputed value.
Not all affected benchmarks show performance changes:
BM_Group_Match 0.53ns ± 1% 0.53ns ± 0% -0.42% (p=0.038 n=10+10)
BM_Group_MatchEmpty 0.26ns ± 1% 0.26ns ± 1% ~ (p=1.000 n=10+10)
BM_Group_MatchEmptyOrDeleted 0.26ns ± 1% 0.26ns ± 1% ~ (p=0.121 n=10+10)
BM_Group_CountLeadingEmptyOrDeleted 0.26ns ± 1% 0.45ns ± 0% +70.05% (p=0.000 n=10+8)
BM_Group_MatchFirstEmptyOrDeleted 0.26ns ± 0% 0.44ns ± 1% +65.91% (p=0.000 n=8+9)
But inspecting the generated code shows the difference,
e. g. BM_Group_MatchFirstEmptyOrDeleted
Before:
add $0xffffffffffffffff,%rbx
jne 30
After:
pcmpeqd %xmm0,%xmm0
pcmpgtb -0x30(%rbp),%xmm0
pmovmskb %xmm0,%eax
add: 0x23$0xffffffffffffffff,%rbx
jne 40
PiperOrigin-RevId: 416083515
--
122fbff893dc4571b3e75e4b241eb4495b925610 by Abseil Team <absl-team@google.com>:
Put namespace guard in ABSL_DECLARE_FLAG to make declaring a flag in a namespace a compiler error instead of a linker error.
PiperOrigin-RevId: 416036072
--
020fd8a20f5fa319e948846e003391fcb9e03868 by Ilya Tokar <tokarip@google.com>:
Make Cord::InlineRep::set_data unconditionally zero out memory.
Currently there is a single case where we don't zero out memory
as an optimization. Unconditional zeroing doesn't show any changes
in benchmarks, except for the unrelated improvement:
BM_CordPartialCopyToCord/1M/1 12.6ns ± 4% 12.6ns ± 4% ~ (p=0.857 n=16+19)
BM_CordPartialCopyToCord/1M/128 44.9ns ± 7% 45.0ns ± 3% ~ (p=0.468 n=18+17)
BM_CordPartialCopyToCord/1M/1k 64.5ns ± 4% 61.4ns ± 4% -4.82% (p=0.000 n=19+17)
BM_CordPartialCopyToCord/1M/8k 139ns ± 3% 128ns ±15% -7.76% (p=0.009 n=17+20)
BM_CordPartialCopyToCord/1M/16k 193ns ± 6% 168ns ± 6% -13.17% (p=0.000 n=17+17)
BM_CordPartialCopyToCord/4M/16k 199ns ± 4% 177ns ± 4% -11.36% (p=0.000 n=17+18)
BM_CordPartialCopyToCord/4M/32k 275ns ± 3% 250ns ± 4% -9.00% (p=0.000 n=18+18)
BM_CordPartialCopyToCord/4M/64k 291ns ± 4% 266ns ± 5% -8.53% (p=0.000 n=18+16)
BM_CordPartialCopyToCord/4M/128k 322ns ± 5% 291ns ± 4% -9.43% (p=0.000 n=20+18)
BM_CordPartialCopyToCord/8M/32k 281ns ± 5% 251ns ± 4% -10.38% (p=0.000 n=20+16)
BM_CordPartialCopyToCord/8M/64k 293ns ± 6% 267ns ± 4% -8.87% (p=0.000 n=16+19)
BM_CordPartialCopyToCord/8M/128k 334ns ± 3% 305ns ± 2% -8.56% (p=0.000 n=17+16)
This is clearly an alignmnet effect since number of the executed instructions is the same:
M_CordPartialCopyToCord/1M/1 155 ± 0% 155 ± 0% ~ (all samples are equal)
BM_CordPartialCopyToCord/1M/128 446 ± 0% 446 ± 0% ~ (p=0.332 n=36+39)
BM_CordPartialCopyToCord/1M/1k 473 ± 0% 473 ± 0% ~ (p=0.969 n=40+40)
BM_CordPartialCopyToCord/1M/8k 808 ± 0% 808 ± 0% ~ (p=0.127 n=40+39)
BM_CordPartialCopyToCord/1M/16k 957 ± 0% 957 ± 0% ~ (p=0.532 n=40+40)
BM_CordPartialCopyToCord/4M/16k 952 ± 0% 952 ± 0% ~ (p=0.686 n=39+39)
BM_CordPartialCopyToCord/4M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.690 n=40+40)
BM_CordPartialCopyToCord/4M/64k 1.23k ± 0% 1.23k ± 0% ~ (p=0.182 n=40+39)
BM_CordPartialCopyToCord/4M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.711 n=40+40)
BM_CordPartialCopyToCord/8M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.697 n=40+40)
BM_CordPartialCopyToCord/8M/64k 1.23k ± 0% 1.23k ± 0% +0.00% (p=0.049 n=40+40)
BM_CordPartialCopyToCord/8M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.507 n=40+40)
This makes code simpler and doesn't regress performance.
PiperOrigin-RevId: 415560574
--
37305b2690b31682088749e4d62f40d7095bdc54 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 415558737
--
86aaed569b9e743c1eb813a5f48def978a793db3 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415515201
--
6cdb8786cdcb4fa0b8a4b72fc98940877d1fdeff by Abseil Team <absl-team@google.com>:
Update SubmitMutexProfileData to accept wait_cycles instead of wait_timestamp
PiperOrigin-RevId: 415360871
--
9f979d307aa16ad09f214e04876cbe84395c0901 by Abseil Team <absl-team@google.com>:
absl::flat_hash_set compiles with -Wconversion -Wsign-compare
PiperOrigin-RevId: 415357498
--
9eceb14174708f15e61259d449b214a8a4c7f9e7 by Abseil Team <absl-team@google.com>:
Fix AddressIsReadable for the corner case of (aligned) addr == NULL.
PiperOrigin-RevId: 415307792
--
1a39ffe55898375e2d7f88c17c99db5a1b95b313 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415162872
--
64378549b110d5f5762185a5906c520fba70f0e7 by Abseil Team <absl-team@google.com>:
Fix a typo in the comments
PiperOrigin-RevId: 415088461
--
41aae8322e913b82710153c22b97c611fdb6e1fb by Abseil Team <absl-team@google.com>:
Switch from `connect` to `rt_sigreturn` -- the latter is much less problematic
for system call sandboxes.
PiperOrigin-RevId: 415073965
--
870c5e3388b6a35611bff538626fe7a1c8c87171 by Abseil Team <absl-team@google.com>:
Add ABSL_HAVE_HWADDRESS_SANITIZER and ABSL_HAVE_LEAK_SANITIZER
PiperOrigin-RevId: 414871189
--
f213ed60a66b58da7ac40555adfb1d529ff0a4db by Derek Mauro <dmauro@google.com>:
Remove reference to __SANITIZE_MEMORY__, which does not exist
It appears to have been copied by pattern matching from the ASAN/TSAN
code blocks.
https://github.com/gcc-mirror/gcc/blob/f47662204de27f7685699eeef89aa173ccf32d85/gcc/cppbuiltin.c#L79-L126
PiperOrigin-RevId: 414806587
--
b152891e73ab515f397ceb53f66c8ee2f33863ea by Abseil Team <absl-team@google.com>:
Rollback previous commit: SYS_open is not defined in certain environments.
PiperOrigin-RevId: 414521820
--
5a1cbb282331023902e1374dd0d920c4effbe47f by Abseil Team <absl-team@google.com>:
Use syscall(SYS_open, ...) instead of open() to avoid possible symbol
interposition.
Also add some warning notes.
PiperOrigin-RevId: 414508186
--
1824d6593612710aafdc599a89b0adced7d787f6 by Abseil Team <absl-team@google.com>:
Correct aarch64 macro check
The macro is __aarch64__, not __arch64__.
PiperOrigin-RevId: 414446225
--
a1536a57b64dfd53945d33a01cfc08b18c99c97b by Abseil Team <absl-team@google.com>:
Fix backwards comment in the last commit.
PiperOrigin-RevId: 414281214
--
11ac021ba779513667a31cf2563ddafc57d6d913 by Abseil Team <absl-team@google.com>:
AddressIsReadable() didn't work correctly on ARM when the given pointer was
misaligned at the end of the page.
Fix that by aligning the pointer on an 8-byte boundary before checking it.
PiperOrigin-RevId: 414203863
GitOrigin-RevId: 07240ca7822d007cdcc79f2c40bd58b2c2010348
Change-Id: If5f129194d59f5c9e5d84efd8cd9e17a70e072ab
3 years ago
|
|
|
// to it. Requires `data` to be non-empty.
|
|
|
|
template <typename Releaser>
|
|
|
|
// NOLINTNEXTLINE - suppress clang-tidy raw pointer return.
|
|
|
|
CordRep* NewExternalRep(absl::string_view data, Releaser&& releaser) {
|
Export of internal Abseil changes
--
07240ca7822d007cdcc79f2c40bd58b2c2010348 by Abseil Team <absl-team@google.com>:
Correct the comment from "AlphaNum" to "Arg".
PiperOrigin-RevId: 416139192
--
adcba4a6b3763626e1db7b1e8c108b3114903557 by Martijn Vels <mvels@google.com>:
Fix NewExternalRep() to require data being non-empty, and remove nullptr return.
PiperOrigin-RevId: 416135865
--
c0d14cd918fb16f15d1d84de9284b5c5ecc1f8f2 by Abseil Team <absl-team@google.com>:
Fix doc comment for absl::ascii_isprint().
The comment was incorrectly saying that it includes all whitespace.
It doesn't; the only whitespace char it includes is ' '.
PiperOrigin-RevId: 416112524
--
d83327800159c07002b6865e21232a12463e02dd by Abseil Team <absl-team@google.com>:
Internal change
PiperOrigin-RevId: 416099978
--
baf11e9ca42ca9140cdbf8075f971db8d65b1195 by Ilya Tokar <tokarip@google.com>:
Prevent compiler from optimizing Group_Match* benchmarks away.
Currently we benchmark single store of precomputed value.
Not all affected benchmarks show performance changes:
BM_Group_Match 0.53ns ± 1% 0.53ns ± 0% -0.42% (p=0.038 n=10+10)
BM_Group_MatchEmpty 0.26ns ± 1% 0.26ns ± 1% ~ (p=1.000 n=10+10)
BM_Group_MatchEmptyOrDeleted 0.26ns ± 1% 0.26ns ± 1% ~ (p=0.121 n=10+10)
BM_Group_CountLeadingEmptyOrDeleted 0.26ns ± 1% 0.45ns ± 0% +70.05% (p=0.000 n=10+8)
BM_Group_MatchFirstEmptyOrDeleted 0.26ns ± 0% 0.44ns ± 1% +65.91% (p=0.000 n=8+9)
But inspecting the generated code shows the difference,
e. g. BM_Group_MatchFirstEmptyOrDeleted
Before:
add $0xffffffffffffffff,%rbx
jne 30
After:
pcmpeqd %xmm0,%xmm0
pcmpgtb -0x30(%rbp),%xmm0
pmovmskb %xmm0,%eax
add: 0x23$0xffffffffffffffff,%rbx
jne 40
PiperOrigin-RevId: 416083515
--
122fbff893dc4571b3e75e4b241eb4495b925610 by Abseil Team <absl-team@google.com>:
Put namespace guard in ABSL_DECLARE_FLAG to make declaring a flag in a namespace a compiler error instead of a linker error.
PiperOrigin-RevId: 416036072
--
020fd8a20f5fa319e948846e003391fcb9e03868 by Ilya Tokar <tokarip@google.com>:
Make Cord::InlineRep::set_data unconditionally zero out memory.
Currently there is a single case where we don't zero out memory
as an optimization. Unconditional zeroing doesn't show any changes
in benchmarks, except for the unrelated improvement:
BM_CordPartialCopyToCord/1M/1 12.6ns ± 4% 12.6ns ± 4% ~ (p=0.857 n=16+19)
BM_CordPartialCopyToCord/1M/128 44.9ns ± 7% 45.0ns ± 3% ~ (p=0.468 n=18+17)
BM_CordPartialCopyToCord/1M/1k 64.5ns ± 4% 61.4ns ± 4% -4.82% (p=0.000 n=19+17)
BM_CordPartialCopyToCord/1M/8k 139ns ± 3% 128ns ±15% -7.76% (p=0.009 n=17+20)
BM_CordPartialCopyToCord/1M/16k 193ns ± 6% 168ns ± 6% -13.17% (p=0.000 n=17+17)
BM_CordPartialCopyToCord/4M/16k 199ns ± 4% 177ns ± 4% -11.36% (p=0.000 n=17+18)
BM_CordPartialCopyToCord/4M/32k 275ns ± 3% 250ns ± 4% -9.00% (p=0.000 n=18+18)
BM_CordPartialCopyToCord/4M/64k 291ns ± 4% 266ns ± 5% -8.53% (p=0.000 n=18+16)
BM_CordPartialCopyToCord/4M/128k 322ns ± 5% 291ns ± 4% -9.43% (p=0.000 n=20+18)
BM_CordPartialCopyToCord/8M/32k 281ns ± 5% 251ns ± 4% -10.38% (p=0.000 n=20+16)
BM_CordPartialCopyToCord/8M/64k 293ns ± 6% 267ns ± 4% -8.87% (p=0.000 n=16+19)
BM_CordPartialCopyToCord/8M/128k 334ns ± 3% 305ns ± 2% -8.56% (p=0.000 n=17+16)
This is clearly an alignmnet effect since number of the executed instructions is the same:
M_CordPartialCopyToCord/1M/1 155 ± 0% 155 ± 0% ~ (all samples are equal)
BM_CordPartialCopyToCord/1M/128 446 ± 0% 446 ± 0% ~ (p=0.332 n=36+39)
BM_CordPartialCopyToCord/1M/1k 473 ± 0% 473 ± 0% ~ (p=0.969 n=40+40)
BM_CordPartialCopyToCord/1M/8k 808 ± 0% 808 ± 0% ~ (p=0.127 n=40+39)
BM_CordPartialCopyToCord/1M/16k 957 ± 0% 957 ± 0% ~ (p=0.532 n=40+40)
BM_CordPartialCopyToCord/4M/16k 952 ± 0% 952 ± 0% ~ (p=0.686 n=39+39)
BM_CordPartialCopyToCord/4M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.690 n=40+40)
BM_CordPartialCopyToCord/4M/64k 1.23k ± 0% 1.23k ± 0% ~ (p=0.182 n=40+39)
BM_CordPartialCopyToCord/4M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.711 n=40+40)
BM_CordPartialCopyToCord/8M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.697 n=40+40)
BM_CordPartialCopyToCord/8M/64k 1.23k ± 0% 1.23k ± 0% +0.00% (p=0.049 n=40+40)
BM_CordPartialCopyToCord/8M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.507 n=40+40)
This makes code simpler and doesn't regress performance.
PiperOrigin-RevId: 415560574
--
37305b2690b31682088749e4d62f40d7095bdc54 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 415558737
--
86aaed569b9e743c1eb813a5f48def978a793db3 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415515201
--
6cdb8786cdcb4fa0b8a4b72fc98940877d1fdeff by Abseil Team <absl-team@google.com>:
Update SubmitMutexProfileData to accept wait_cycles instead of wait_timestamp
PiperOrigin-RevId: 415360871
--
9f979d307aa16ad09f214e04876cbe84395c0901 by Abseil Team <absl-team@google.com>:
absl::flat_hash_set compiles with -Wconversion -Wsign-compare
PiperOrigin-RevId: 415357498
--
9eceb14174708f15e61259d449b214a8a4c7f9e7 by Abseil Team <absl-team@google.com>:
Fix AddressIsReadable for the corner case of (aligned) addr == NULL.
PiperOrigin-RevId: 415307792
--
1a39ffe55898375e2d7f88c17c99db5a1b95b313 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415162872
--
64378549b110d5f5762185a5906c520fba70f0e7 by Abseil Team <absl-team@google.com>:
Fix a typo in the comments
PiperOrigin-RevId: 415088461
--
41aae8322e913b82710153c22b97c611fdb6e1fb by Abseil Team <absl-team@google.com>:
Switch from `connect` to `rt_sigreturn` -- the latter is much less problematic
for system call sandboxes.
PiperOrigin-RevId: 415073965
--
870c5e3388b6a35611bff538626fe7a1c8c87171 by Abseil Team <absl-team@google.com>:
Add ABSL_HAVE_HWADDRESS_SANITIZER and ABSL_HAVE_LEAK_SANITIZER
PiperOrigin-RevId: 414871189
--
f213ed60a66b58da7ac40555adfb1d529ff0a4db by Derek Mauro <dmauro@google.com>:
Remove reference to __SANITIZE_MEMORY__, which does not exist
It appears to have been copied by pattern matching from the ASAN/TSAN
code blocks.
https://github.com/gcc-mirror/gcc/blob/f47662204de27f7685699eeef89aa173ccf32d85/gcc/cppbuiltin.c#L79-L126
PiperOrigin-RevId: 414806587
--
b152891e73ab515f397ceb53f66c8ee2f33863ea by Abseil Team <absl-team@google.com>:
Rollback previous commit: SYS_open is not defined in certain environments.
PiperOrigin-RevId: 414521820
--
5a1cbb282331023902e1374dd0d920c4effbe47f by Abseil Team <absl-team@google.com>:
Use syscall(SYS_open, ...) instead of open() to avoid possible symbol
interposition.
Also add some warning notes.
PiperOrigin-RevId: 414508186
--
1824d6593612710aafdc599a89b0adced7d787f6 by Abseil Team <absl-team@google.com>:
Correct aarch64 macro check
The macro is __aarch64__, not __arch64__.
PiperOrigin-RevId: 414446225
--
a1536a57b64dfd53945d33a01cfc08b18c99c97b by Abseil Team <absl-team@google.com>:
Fix backwards comment in the last commit.
PiperOrigin-RevId: 414281214
--
11ac021ba779513667a31cf2563ddafc57d6d913 by Abseil Team <absl-team@google.com>:
AddressIsReadable() didn't work correctly on ARM when the given pointer was
misaligned at the end of the page.
Fix that by aligning the pointer on an 8-byte boundary before checking it.
PiperOrigin-RevId: 414203863
GitOrigin-RevId: 07240ca7822d007cdcc79f2c40bd58b2c2010348
Change-Id: If5f129194d59f5c9e5d84efd8cd9e17a70e072ab
3 years ago
|
|
|
assert(!data.empty());
|
|
|
|
using ReleaserType = absl::decay_t<Releaser>;
|
|
|
|
CordRepExternal* rep = new CordRepExternalImpl<ReleaserType>(
|
|
|
|
std::forward<Releaser>(releaser), 0);
|
|
|
|
InitializeCordRepExternal(data, rep);
|
|
|
|
return rep;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overload for function reference types that dispatches using a function
|
|
|
|
// pointer because there are no `alignof()` or `sizeof()` a function reference.
|
|
|
|
// NOLINTNEXTLINE - suppress clang-tidy raw pointer return.
|
|
|
|
inline CordRep* NewExternalRep(absl::string_view data,
|
|
|
|
void (&releaser)(absl::string_view)) {
|
|
|
|
return NewExternalRep(data, &releaser);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace cord_internal
|
|
|
|
|
|
|
|
template <typename Releaser>
|
|
|
|
Cord MakeCordFromExternal(absl::string_view data, Releaser&& releaser) {
|
|
|
|
Cord cord;
|
Export of internal Abseil changes
--
07240ca7822d007cdcc79f2c40bd58b2c2010348 by Abseil Team <absl-team@google.com>:
Correct the comment from "AlphaNum" to "Arg".
PiperOrigin-RevId: 416139192
--
adcba4a6b3763626e1db7b1e8c108b3114903557 by Martijn Vels <mvels@google.com>:
Fix NewExternalRep() to require data being non-empty, and remove nullptr return.
PiperOrigin-RevId: 416135865
--
c0d14cd918fb16f15d1d84de9284b5c5ecc1f8f2 by Abseil Team <absl-team@google.com>:
Fix doc comment for absl::ascii_isprint().
The comment was incorrectly saying that it includes all whitespace.
It doesn't; the only whitespace char it includes is ' '.
PiperOrigin-RevId: 416112524
--
d83327800159c07002b6865e21232a12463e02dd by Abseil Team <absl-team@google.com>:
Internal change
PiperOrigin-RevId: 416099978
--
baf11e9ca42ca9140cdbf8075f971db8d65b1195 by Ilya Tokar <tokarip@google.com>:
Prevent compiler from optimizing Group_Match* benchmarks away.
Currently we benchmark single store of precomputed value.
Not all affected benchmarks show performance changes:
BM_Group_Match 0.53ns ± 1% 0.53ns ± 0% -0.42% (p=0.038 n=10+10)
BM_Group_MatchEmpty 0.26ns ± 1% 0.26ns ± 1% ~ (p=1.000 n=10+10)
BM_Group_MatchEmptyOrDeleted 0.26ns ± 1% 0.26ns ± 1% ~ (p=0.121 n=10+10)
BM_Group_CountLeadingEmptyOrDeleted 0.26ns ± 1% 0.45ns ± 0% +70.05% (p=0.000 n=10+8)
BM_Group_MatchFirstEmptyOrDeleted 0.26ns ± 0% 0.44ns ± 1% +65.91% (p=0.000 n=8+9)
But inspecting the generated code shows the difference,
e. g. BM_Group_MatchFirstEmptyOrDeleted
Before:
add $0xffffffffffffffff,%rbx
jne 30
After:
pcmpeqd %xmm0,%xmm0
pcmpgtb -0x30(%rbp),%xmm0
pmovmskb %xmm0,%eax
add: 0x23$0xffffffffffffffff,%rbx
jne 40
PiperOrigin-RevId: 416083515
--
122fbff893dc4571b3e75e4b241eb4495b925610 by Abseil Team <absl-team@google.com>:
Put namespace guard in ABSL_DECLARE_FLAG to make declaring a flag in a namespace a compiler error instead of a linker error.
PiperOrigin-RevId: 416036072
--
020fd8a20f5fa319e948846e003391fcb9e03868 by Ilya Tokar <tokarip@google.com>:
Make Cord::InlineRep::set_data unconditionally zero out memory.
Currently there is a single case where we don't zero out memory
as an optimization. Unconditional zeroing doesn't show any changes
in benchmarks, except for the unrelated improvement:
BM_CordPartialCopyToCord/1M/1 12.6ns ± 4% 12.6ns ± 4% ~ (p=0.857 n=16+19)
BM_CordPartialCopyToCord/1M/128 44.9ns ± 7% 45.0ns ± 3% ~ (p=0.468 n=18+17)
BM_CordPartialCopyToCord/1M/1k 64.5ns ± 4% 61.4ns ± 4% -4.82% (p=0.000 n=19+17)
BM_CordPartialCopyToCord/1M/8k 139ns ± 3% 128ns ±15% -7.76% (p=0.009 n=17+20)
BM_CordPartialCopyToCord/1M/16k 193ns ± 6% 168ns ± 6% -13.17% (p=0.000 n=17+17)
BM_CordPartialCopyToCord/4M/16k 199ns ± 4% 177ns ± 4% -11.36% (p=0.000 n=17+18)
BM_CordPartialCopyToCord/4M/32k 275ns ± 3% 250ns ± 4% -9.00% (p=0.000 n=18+18)
BM_CordPartialCopyToCord/4M/64k 291ns ± 4% 266ns ± 5% -8.53% (p=0.000 n=18+16)
BM_CordPartialCopyToCord/4M/128k 322ns ± 5% 291ns ± 4% -9.43% (p=0.000 n=20+18)
BM_CordPartialCopyToCord/8M/32k 281ns ± 5% 251ns ± 4% -10.38% (p=0.000 n=20+16)
BM_CordPartialCopyToCord/8M/64k 293ns ± 6% 267ns ± 4% -8.87% (p=0.000 n=16+19)
BM_CordPartialCopyToCord/8M/128k 334ns ± 3% 305ns ± 2% -8.56% (p=0.000 n=17+16)
This is clearly an alignmnet effect since number of the executed instructions is the same:
M_CordPartialCopyToCord/1M/1 155 ± 0% 155 ± 0% ~ (all samples are equal)
BM_CordPartialCopyToCord/1M/128 446 ± 0% 446 ± 0% ~ (p=0.332 n=36+39)
BM_CordPartialCopyToCord/1M/1k 473 ± 0% 473 ± 0% ~ (p=0.969 n=40+40)
BM_CordPartialCopyToCord/1M/8k 808 ± 0% 808 ± 0% ~ (p=0.127 n=40+39)
BM_CordPartialCopyToCord/1M/16k 957 ± 0% 957 ± 0% ~ (p=0.532 n=40+40)
BM_CordPartialCopyToCord/4M/16k 952 ± 0% 952 ± 0% ~ (p=0.686 n=39+39)
BM_CordPartialCopyToCord/4M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.690 n=40+40)
BM_CordPartialCopyToCord/4M/64k 1.23k ± 0% 1.23k ± 0% ~ (p=0.182 n=40+39)
BM_CordPartialCopyToCord/4M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.711 n=40+40)
BM_CordPartialCopyToCord/8M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.697 n=40+40)
BM_CordPartialCopyToCord/8M/64k 1.23k ± 0% 1.23k ± 0% +0.00% (p=0.049 n=40+40)
BM_CordPartialCopyToCord/8M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.507 n=40+40)
This makes code simpler and doesn't regress performance.
PiperOrigin-RevId: 415560574
--
37305b2690b31682088749e4d62f40d7095bdc54 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 415558737
--
86aaed569b9e743c1eb813a5f48def978a793db3 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415515201
--
6cdb8786cdcb4fa0b8a4b72fc98940877d1fdeff by Abseil Team <absl-team@google.com>:
Update SubmitMutexProfileData to accept wait_cycles instead of wait_timestamp
PiperOrigin-RevId: 415360871
--
9f979d307aa16ad09f214e04876cbe84395c0901 by Abseil Team <absl-team@google.com>:
absl::flat_hash_set compiles with -Wconversion -Wsign-compare
PiperOrigin-RevId: 415357498
--
9eceb14174708f15e61259d449b214a8a4c7f9e7 by Abseil Team <absl-team@google.com>:
Fix AddressIsReadable for the corner case of (aligned) addr == NULL.
PiperOrigin-RevId: 415307792
--
1a39ffe55898375e2d7f88c17c99db5a1b95b313 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415162872
--
64378549b110d5f5762185a5906c520fba70f0e7 by Abseil Team <absl-team@google.com>:
Fix a typo in the comments
PiperOrigin-RevId: 415088461
--
41aae8322e913b82710153c22b97c611fdb6e1fb by Abseil Team <absl-team@google.com>:
Switch from `connect` to `rt_sigreturn` -- the latter is much less problematic
for system call sandboxes.
PiperOrigin-RevId: 415073965
--
870c5e3388b6a35611bff538626fe7a1c8c87171 by Abseil Team <absl-team@google.com>:
Add ABSL_HAVE_HWADDRESS_SANITIZER and ABSL_HAVE_LEAK_SANITIZER
PiperOrigin-RevId: 414871189
--
f213ed60a66b58da7ac40555adfb1d529ff0a4db by Derek Mauro <dmauro@google.com>:
Remove reference to __SANITIZE_MEMORY__, which does not exist
It appears to have been copied by pattern matching from the ASAN/TSAN
code blocks.
https://github.com/gcc-mirror/gcc/blob/f47662204de27f7685699eeef89aa173ccf32d85/gcc/cppbuiltin.c#L79-L126
PiperOrigin-RevId: 414806587
--
b152891e73ab515f397ceb53f66c8ee2f33863ea by Abseil Team <absl-team@google.com>:
Rollback previous commit: SYS_open is not defined in certain environments.
PiperOrigin-RevId: 414521820
--
5a1cbb282331023902e1374dd0d920c4effbe47f by Abseil Team <absl-team@google.com>:
Use syscall(SYS_open, ...) instead of open() to avoid possible symbol
interposition.
Also add some warning notes.
PiperOrigin-RevId: 414508186
--
1824d6593612710aafdc599a89b0adced7d787f6 by Abseil Team <absl-team@google.com>:
Correct aarch64 macro check
The macro is __aarch64__, not __arch64__.
PiperOrigin-RevId: 414446225
--
a1536a57b64dfd53945d33a01cfc08b18c99c97b by Abseil Team <absl-team@google.com>:
Fix backwards comment in the last commit.
PiperOrigin-RevId: 414281214
--
11ac021ba779513667a31cf2563ddafc57d6d913 by Abseil Team <absl-team@google.com>:
AddressIsReadable() didn't work correctly on ARM when the given pointer was
misaligned at the end of the page.
Fix that by aligning the pointer on an 8-byte boundary before checking it.
PiperOrigin-RevId: 414203863
GitOrigin-RevId: 07240ca7822d007cdcc79f2c40bd58b2c2010348
Change-Id: If5f129194d59f5c9e5d84efd8cd9e17a70e072ab
3 years ago
|
|
|
if (ABSL_PREDICT_TRUE(!data.empty())) {
|
|
|
|
cord.contents_.EmplaceTree(::absl::cord_internal::NewExternalRep(
|
|
|
|
data, std::forward<Releaser>(releaser)),
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
Cord::MethodIdentifier::kMakeCordFromExternal);
|
Export of internal Abseil changes
--
07240ca7822d007cdcc79f2c40bd58b2c2010348 by Abseil Team <absl-team@google.com>:
Correct the comment from "AlphaNum" to "Arg".
PiperOrigin-RevId: 416139192
--
adcba4a6b3763626e1db7b1e8c108b3114903557 by Martijn Vels <mvels@google.com>:
Fix NewExternalRep() to require data being non-empty, and remove nullptr return.
PiperOrigin-RevId: 416135865
--
c0d14cd918fb16f15d1d84de9284b5c5ecc1f8f2 by Abseil Team <absl-team@google.com>:
Fix doc comment for absl::ascii_isprint().
The comment was incorrectly saying that it includes all whitespace.
It doesn't; the only whitespace char it includes is ' '.
PiperOrigin-RevId: 416112524
--
d83327800159c07002b6865e21232a12463e02dd by Abseil Team <absl-team@google.com>:
Internal change
PiperOrigin-RevId: 416099978
--
baf11e9ca42ca9140cdbf8075f971db8d65b1195 by Ilya Tokar <tokarip@google.com>:
Prevent compiler from optimizing Group_Match* benchmarks away.
Currently we benchmark single store of precomputed value.
Not all affected benchmarks show performance changes:
BM_Group_Match 0.53ns ± 1% 0.53ns ± 0% -0.42% (p=0.038 n=10+10)
BM_Group_MatchEmpty 0.26ns ± 1% 0.26ns ± 1% ~ (p=1.000 n=10+10)
BM_Group_MatchEmptyOrDeleted 0.26ns ± 1% 0.26ns ± 1% ~ (p=0.121 n=10+10)
BM_Group_CountLeadingEmptyOrDeleted 0.26ns ± 1% 0.45ns ± 0% +70.05% (p=0.000 n=10+8)
BM_Group_MatchFirstEmptyOrDeleted 0.26ns ± 0% 0.44ns ± 1% +65.91% (p=0.000 n=8+9)
But inspecting the generated code shows the difference,
e. g. BM_Group_MatchFirstEmptyOrDeleted
Before:
add $0xffffffffffffffff,%rbx
jne 30
After:
pcmpeqd %xmm0,%xmm0
pcmpgtb -0x30(%rbp),%xmm0
pmovmskb %xmm0,%eax
add: 0x23$0xffffffffffffffff,%rbx
jne 40
PiperOrigin-RevId: 416083515
--
122fbff893dc4571b3e75e4b241eb4495b925610 by Abseil Team <absl-team@google.com>:
Put namespace guard in ABSL_DECLARE_FLAG to make declaring a flag in a namespace a compiler error instead of a linker error.
PiperOrigin-RevId: 416036072
--
020fd8a20f5fa319e948846e003391fcb9e03868 by Ilya Tokar <tokarip@google.com>:
Make Cord::InlineRep::set_data unconditionally zero out memory.
Currently there is a single case where we don't zero out memory
as an optimization. Unconditional zeroing doesn't show any changes
in benchmarks, except for the unrelated improvement:
BM_CordPartialCopyToCord/1M/1 12.6ns ± 4% 12.6ns ± 4% ~ (p=0.857 n=16+19)
BM_CordPartialCopyToCord/1M/128 44.9ns ± 7% 45.0ns ± 3% ~ (p=0.468 n=18+17)
BM_CordPartialCopyToCord/1M/1k 64.5ns ± 4% 61.4ns ± 4% -4.82% (p=0.000 n=19+17)
BM_CordPartialCopyToCord/1M/8k 139ns ± 3% 128ns ±15% -7.76% (p=0.009 n=17+20)
BM_CordPartialCopyToCord/1M/16k 193ns ± 6% 168ns ± 6% -13.17% (p=0.000 n=17+17)
BM_CordPartialCopyToCord/4M/16k 199ns ± 4% 177ns ± 4% -11.36% (p=0.000 n=17+18)
BM_CordPartialCopyToCord/4M/32k 275ns ± 3% 250ns ± 4% -9.00% (p=0.000 n=18+18)
BM_CordPartialCopyToCord/4M/64k 291ns ± 4% 266ns ± 5% -8.53% (p=0.000 n=18+16)
BM_CordPartialCopyToCord/4M/128k 322ns ± 5% 291ns ± 4% -9.43% (p=0.000 n=20+18)
BM_CordPartialCopyToCord/8M/32k 281ns ± 5% 251ns ± 4% -10.38% (p=0.000 n=20+16)
BM_CordPartialCopyToCord/8M/64k 293ns ± 6% 267ns ± 4% -8.87% (p=0.000 n=16+19)
BM_CordPartialCopyToCord/8M/128k 334ns ± 3% 305ns ± 2% -8.56% (p=0.000 n=17+16)
This is clearly an alignmnet effect since number of the executed instructions is the same:
M_CordPartialCopyToCord/1M/1 155 ± 0% 155 ± 0% ~ (all samples are equal)
BM_CordPartialCopyToCord/1M/128 446 ± 0% 446 ± 0% ~ (p=0.332 n=36+39)
BM_CordPartialCopyToCord/1M/1k 473 ± 0% 473 ± 0% ~ (p=0.969 n=40+40)
BM_CordPartialCopyToCord/1M/8k 808 ± 0% 808 ± 0% ~ (p=0.127 n=40+39)
BM_CordPartialCopyToCord/1M/16k 957 ± 0% 957 ± 0% ~ (p=0.532 n=40+40)
BM_CordPartialCopyToCord/4M/16k 952 ± 0% 952 ± 0% ~ (p=0.686 n=39+39)
BM_CordPartialCopyToCord/4M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.690 n=40+40)
BM_CordPartialCopyToCord/4M/64k 1.23k ± 0% 1.23k ± 0% ~ (p=0.182 n=40+39)
BM_CordPartialCopyToCord/4M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.711 n=40+40)
BM_CordPartialCopyToCord/8M/32k 1.12k ± 0% 1.12k ± 0% ~ (p=0.697 n=40+40)
BM_CordPartialCopyToCord/8M/64k 1.23k ± 0% 1.23k ± 0% +0.00% (p=0.049 n=40+40)
BM_CordPartialCopyToCord/8M/128k 1.44k ± 0% 1.44k ± 0% ~ (p=0.507 n=40+40)
This makes code simpler and doesn't regress performance.
PiperOrigin-RevId: 415560574
--
37305b2690b31682088749e4d62f40d7095bdc54 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 415558737
--
86aaed569b9e743c1eb813a5f48def978a793db3 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415515201
--
6cdb8786cdcb4fa0b8a4b72fc98940877d1fdeff by Abseil Team <absl-team@google.com>:
Update SubmitMutexProfileData to accept wait_cycles instead of wait_timestamp
PiperOrigin-RevId: 415360871
--
9f979d307aa16ad09f214e04876cbe84395c0901 by Abseil Team <absl-team@google.com>:
absl::flat_hash_set compiles with -Wconversion -Wsign-compare
PiperOrigin-RevId: 415357498
--
9eceb14174708f15e61259d449b214a8a4c7f9e7 by Abseil Team <absl-team@google.com>:
Fix AddressIsReadable for the corner case of (aligned) addr == NULL.
PiperOrigin-RevId: 415307792
--
1a39ffe55898375e2d7f88c17c99db5a1b95b313 by Martijn Vels <mvels@google.com>:
Internal change
PiperOrigin-RevId: 415162872
--
64378549b110d5f5762185a5906c520fba70f0e7 by Abseil Team <absl-team@google.com>:
Fix a typo in the comments
PiperOrigin-RevId: 415088461
--
41aae8322e913b82710153c22b97c611fdb6e1fb by Abseil Team <absl-team@google.com>:
Switch from `connect` to `rt_sigreturn` -- the latter is much less problematic
for system call sandboxes.
PiperOrigin-RevId: 415073965
--
870c5e3388b6a35611bff538626fe7a1c8c87171 by Abseil Team <absl-team@google.com>:
Add ABSL_HAVE_HWADDRESS_SANITIZER and ABSL_HAVE_LEAK_SANITIZER
PiperOrigin-RevId: 414871189
--
f213ed60a66b58da7ac40555adfb1d529ff0a4db by Derek Mauro <dmauro@google.com>:
Remove reference to __SANITIZE_MEMORY__, which does not exist
It appears to have been copied by pattern matching from the ASAN/TSAN
code blocks.
https://github.com/gcc-mirror/gcc/blob/f47662204de27f7685699eeef89aa173ccf32d85/gcc/cppbuiltin.c#L79-L126
PiperOrigin-RevId: 414806587
--
b152891e73ab515f397ceb53f66c8ee2f33863ea by Abseil Team <absl-team@google.com>:
Rollback previous commit: SYS_open is not defined in certain environments.
PiperOrigin-RevId: 414521820
--
5a1cbb282331023902e1374dd0d920c4effbe47f by Abseil Team <absl-team@google.com>:
Use syscall(SYS_open, ...) instead of open() to avoid possible symbol
interposition.
Also add some warning notes.
PiperOrigin-RevId: 414508186
--
1824d6593612710aafdc599a89b0adced7d787f6 by Abseil Team <absl-team@google.com>:
Correct aarch64 macro check
The macro is __aarch64__, not __arch64__.
PiperOrigin-RevId: 414446225
--
a1536a57b64dfd53945d33a01cfc08b18c99c97b by Abseil Team <absl-team@google.com>:
Fix backwards comment in the last commit.
PiperOrigin-RevId: 414281214
--
11ac021ba779513667a31cf2563ddafc57d6d913 by Abseil Team <absl-team@google.com>:
AddressIsReadable() didn't work correctly on ARM when the given pointer was
misaligned at the end of the page.
Fix that by aligning the pointer on an 8-byte boundary before checking it.
PiperOrigin-RevId: 414203863
GitOrigin-RevId: 07240ca7822d007cdcc79f2c40bd58b2c2010348
Change-Id: If5f129194d59f5c9e5d84efd8cd9e17a70e072ab
3 years ago
|
|
|
} else {
|
|
|
|
using ReleaserType = absl::decay_t<Releaser>;
|
|
|
|
cord_internal::InvokeReleaser(
|
|
|
|
cord_internal::Rank0{}, ReleaserType(std::forward<Releaser>(releaser)),
|
|
|
|
data);
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
}
|
|
|
|
return cord;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr Cord::InlineRep::InlineRep(cord_internal::InlineData data)
|
|
|
|
: data_(data) {}
|
|
|
|
|
|
|
|
inline Cord::InlineRep::InlineRep(const Cord::InlineRep& src)
|
|
|
|
: data_(InlineData::kDefaultInit) {
|
|
|
|
if (CordRep* tree = src.tree()) {
|
|
|
|
EmplaceTree(CordRep::Ref(tree), src.data_,
|
|
|
|
CordzUpdateTracker::kConstructorCord);
|
|
|
|
} else {
|
|
|
|
data_ = src.data_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::InlineRep::InlineRep(Cord::InlineRep&& src) : data_(src.data_) {
|
|
|
|
src.ResetToEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::InlineRep& Cord::InlineRep::operator=(const Cord::InlineRep& src) {
|
|
|
|
if (this == &src) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
if (!is_tree() && !src.is_tree()) {
|
|
|
|
data_ = src.data_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
AssignSlow(src);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::InlineRep& Cord::InlineRep::operator=(
|
|
|
|
Cord::InlineRep&& src) noexcept {
|
|
|
|
if (is_tree()) {
|
|
|
|
UnrefTree();
|
|
|
|
}
|
|
|
|
data_ = src.data_;
|
|
|
|
src.ResetToEmpty();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::InlineRep::Swap(Cord::InlineRep* rhs) {
|
|
|
|
if (rhs == this) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::swap(data_, rhs->data_);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const char* Cord::InlineRep::data() const {
|
|
|
|
return is_tree() ? nullptr : data_.as_chars();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline absl::cord_internal::CordRep* Cord::InlineRep::as_tree() const {
|
|
|
|
assert(data_.is_tree());
|
|
|
|
return data_.as_tree();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline absl::cord_internal::CordRep* Cord::InlineRep::tree() const {
|
|
|
|
if (is_tree()) {
|
|
|
|
return as_tree();
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Cord::InlineRep::empty() const { return data_.is_empty(); }
|
|
|
|
|
|
|
|
inline size_t Cord::InlineRep::size() const {
|
|
|
|
return is_tree() ? as_tree()->length : inline_size();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline cord_internal::CordRepFlat* Cord::InlineRep::MakeFlatWithExtraCapacity(
|
|
|
|
size_t extra) {
|
|
|
|
static_assert(cord_internal::kMinFlatLength >= sizeof(data_), "");
|
|
|
|
size_t len = data_.inline_size();
|
|
|
|
auto* result = CordRepFlat::New(len + extra);
|
|
|
|
result->length = len;
|
|
|
|
memcpy(result->Data(), data_.as_chars(), sizeof(data_));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::InlineRep::EmplaceTree(CordRep* rep,
|
|
|
|
MethodIdentifier method) {
|
|
|
|
assert(rep);
|
|
|
|
data_.make_tree(rep);
|
|
|
|
CordzInfo::MaybeTrackCord(data_, method);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::InlineRep::EmplaceTree(CordRep* rep, const InlineData& parent,
|
|
|
|
MethodIdentifier method) {
|
|
|
|
data_.make_tree(rep);
|
|
|
|
CordzInfo::MaybeTrackCord(data_, parent, method);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::InlineRep::SetTree(CordRep* rep,
|
|
|
|
const CordzUpdateScope& scope) {
|
|
|
|
assert(rep);
|
|
|
|
assert(data_.is_tree());
|
|
|
|
data_.set_tree(rep);
|
|
|
|
scope.SetCordRep(rep);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::InlineRep::SetTreeOrEmpty(CordRep* rep,
|
|
|
|
const CordzUpdateScope& scope) {
|
|
|
|
assert(data_.is_tree());
|
|
|
|
if (rep) {
|
|
|
|
data_.set_tree(rep);
|
|
|
|
} else {
|
|
|
|
data_ = {};
|
|
|
|
}
|
|
|
|
scope.SetCordRep(rep);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::InlineRep::CommitTree(const CordRep* old_rep, CordRep* rep,
|
|
|
|
const CordzUpdateScope& scope,
|
|
|
|
MethodIdentifier method) {
|
|
|
|
if (old_rep) {
|
|
|
|
SetTree(rep, scope);
|
|
|
|
} else {
|
|
|
|
EmplaceTree(rep, method);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline absl::cord_internal::CordRep* Cord::InlineRep::clear() {
|
|
|
|
if (is_tree()) {
|
|
|
|
CordzInfo::MaybeUntrackCord(cordz_info());
|
|
|
|
}
|
|
|
|
absl::cord_internal::CordRep* result = tree();
|
|
|
|
ResetToEmpty();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::InlineRep::CopyToArray(char* dst) const {
|
|
|
|
assert(!is_tree());
|
|
|
|
size_t n = inline_size();
|
|
|
|
assert(n != 0);
|
|
|
|
cord_internal::SmallMemmove(dst, data_.as_chars(), n);
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr inline Cord::Cord() noexcept {}
|
|
|
|
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
inline Cord::Cord(absl::string_view src)
|
|
|
|
: Cord(src, CordzUpdateTracker::kConstructorString) {}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
constexpr Cord::Cord(strings_internal::StringConstant<T>)
|
|
|
|
: contents_(strings_internal::StringConstant<T>::value.size() <=
|
|
|
|
cord_internal::kMaxInline
|
|
|
|
? cord_internal::InlineData(
|
|
|
|
strings_internal::StringConstant<T>::value)
|
|
|
|
: cord_internal::InlineData(
|
|
|
|
&cord_internal::ConstInitExternalStorage<
|
|
|
|
strings_internal::StringConstant<T>>::value)) {}
|
|
|
|
|
|
|
|
inline Cord& Cord::operator=(const Cord& x) {
|
|
|
|
contents_ = x.contents_;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
Export of internal Abseil changes
--
60b8e77be4bab1bbd3b4c3b70054879229634511 by Derek Mauro <dmauro@google.com>:
Use _MSVC_LANG for some C++ dialect checks since MSVC doesn't
set __cplusplus accurately by default.
https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
See GitHub #722.
PiperOrigin-RevId: 371362181
--
5d736accdff04db0e722f377c0d79f2d3ed53263 by Martijn Vels <mvels@google.com>:
Fix the estimated memory size for CordRepExternal
PiperOrigin-RevId: 371350380
--
eaaa1d8a167aeca67a2aa3a098a2b61a9d72172f by Martijn Vels <mvels@google.com>:
Remove flakes by not enforcing re-allocated pointers do never match original
Tests that do multiple updates could end up with the original allocated pointer on a 2nd resize, so the 'EqIfPrivate' should not assume that if we do 'not' have the capacity that all following relocations will never match the original. We only care about 'pointer unchanged if private and there is capacity', trying to establish 'pointer changed at some point due to re-allocation; is pointless.
PiperOrigin-RevId: 371338965
--
d1837bee6bade1902b095c1cbf64231668bb84c5 by Martijn Vels <mvels@google.com>:
Undo inline of small data copy in cord
This leads to a performance regression as the code is not inlined (absent hard FDO inputs), and there are no suitable tail call options.
PiperOrigin-RevId: 371332332
--
06dc64b833069efc7d18b11df607c8c22be690da by Martijn Vels <mvels@google.com>:
Add final instrumentation for Cordz and remove 'old' cordz logic.
This change instruments the last cord function for cordz. It removes the 'old' functions: set_tree, replace_tree, UpdateCordzStatistics and RecordMetrics.
PiperOrigin-RevId: 371219909
--
a5e0be538579c603052feec03e6d9910c43ea787 by Martijn Vels <mvels@google.com>:
Extend the life of CordRep* if inside a snapshot
If a snapshot (potentially) includes the current CordzInfo, we need to extent the lifetime of the CordRep*, as the snapshot 'point in time' observation of the cord should ideally be preserved.
PiperOrigin-RevId: 371146151
--
74d77a89774cd6c8ecdeebee0193b294a39383d6 by Martijn Vels <mvels@google.com>:
Instrument std::string consuming methods: ctor, operator=, Append and Prepend
This change moves the 'steal into CordRep' logic into a separate function so we can use it directly in the ctor, operator assign and append and prepend, allowing Cordz instrumentation with the proper method attributes.
The assign operator is implemented in AssignLargeString leaving the dispatch inlined in cord.h (which as a side effects also allows clean tail calls in the AssignLargeString method)
PiperOrigin-RevId: 371094756
--
b39effc45266b7ce2e7f96caa3b16cb6e3acc2dd by Martijn Vels <mvels@google.com>:
Add Cordz instrumentation to CordReader
PiperOrigin-RevId: 370990181
GitOrigin-RevId: 60b8e77be4bab1bbd3b4c3b70054879229634511
Change-Id: I96af62e6f1a643e8b1228ae01e6c84e33706bb05
4 years ago
|
|
|
template <typename T, Cord::EnableIfString<T>>
|
|
|
|
Cord& Cord::operator=(T&& src) {
|
|
|
|
if (src.size() <= cord_internal::kMaxBytesToCopy) {
|
|
|
|
return operator=(absl::string_view(src));
|
|
|
|
} else {
|
|
|
|
return AssignLargeString(std::forward<T>(src));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::Cord(const Cord& src) : contents_(src.contents_) {}
|
|
|
|
|
|
|
|
inline Cord::Cord(Cord&& src) noexcept : contents_(std::move(src.contents_)) {}
|
|
|
|
|
|
|
|
inline void Cord::swap(Cord& other) noexcept {
|
|
|
|
contents_.Swap(&other.contents_);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord& Cord::operator=(Cord&& x) noexcept {
|
|
|
|
contents_ = std::move(x.contents_);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
Export of internal Abseil changes
--
7d0468a6610ed85586d5c87fd65de8dac5118923 by Derek Mauro <dmauro@google.com>:
Import of CCTZ from GitHub.
PiperOrigin-RevId: 313226473
--
1131ef6d116f5ce7d46537a82f300ea06dcaaa53 by Gennadiy Rozental <rogeeff@google.com>:
Migrate internal interface to use mutable references.
PiperOrigin-RevId: 312931131
--
96225212a9f5fbd0b38c71fe65539164992c7c3b by Laramie Leavitt <lar@google.com>:
Remove random/internal/distributions.h
This file was something of an historical artifact. All of the related
code has either been removed or migraged, and so the only remaining type
belongs with uniform_helper.h, as it is used to infer the return type
of the absl::Uniform method in a few cases.
PiperOrigin-RevId: 312878173
--
6dcbd5be58ad425e08740ff64088373ee7fe4a72 by Mark Barolak <mbar@google.com>:
Release the StrFormat test case for Cords to open source.
PiperOrigin-RevId: 312707974
--
34484d18dfb63a0a7ad6e2aaeb570e33592968be by Abseil Team <absl-team@google.com>:
Let Cord::Cord(string&&), Cord::operator=(string&&),
Cord::Append(string&&), and Cord::Prepend(string&&) steal string data
and embed it into the Cord as a single external chunk, instead of
copying it into flat chunks (at most 4083-byte each).
Stealing string data is faster, but it creates a long chunk, which leads
to a higher more memory usage if its subcords are created and outlive
the whole Cord.
These functions revert to copying the data if any of the following
conditions holds:
- string size is at most kMaxBytesToCopy (511), to avoid the overhead
of an external chunk for short strings;
- less than half of string capacity is used, to avoid pinning to much
unused memory.
PiperOrigin-RevId: 312683785
GitOrigin-RevId: 7d0468a6610ed85586d5c87fd65de8dac5118923
Change-Id: If79b5a1dfe6d53a8ddddbc7da84338f11fc4cfa3
5 years ago
|
|
|
extern template Cord::Cord(std::string&& src);
|
|
|
|
|
|
|
|
inline size_t Cord::size() const {
|
|
|
|
// Length is 1st field in str.rep_
|
|
|
|
return contents_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Cord::empty() const { return contents_.empty(); }
|
|
|
|
|
|
|
|
inline size_t Cord::EstimatedMemoryUsage(
|
|
|
|
CordMemoryAccounting accounting_method) const {
|
|
|
|
size_t result = sizeof(Cord);
|
|
|
|
if (const absl::cord_internal::CordRep* rep = contents_.tree()) {
|
|
|
|
if (accounting_method == CordMemoryAccounting::kFairShare) {
|
|
|
|
result += cord_internal::GetEstimatedFairShareMemoryUsage(rep);
|
|
|
|
} else {
|
|
|
|
result += cord_internal::GetEstimatedMemoryUsage(rep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline absl::optional<absl::string_view> Cord::TryFlat() const {
|
|
|
|
absl::cord_internal::CordRep* rep = contents_.tree();
|
|
|
|
if (rep == nullptr) {
|
|
|
|
return absl::string_view(contents_.data(), contents_.size());
|
|
|
|
}
|
|
|
|
absl::string_view fragment;
|
|
|
|
if (GetFlatAux(rep, &fragment)) {
|
|
|
|
return fragment;
|
|
|
|
}
|
|
|
|
return absl::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline absl::string_view Cord::Flatten() {
|
|
|
|
absl::cord_internal::CordRep* rep = contents_.tree();
|
|
|
|
if (rep == nullptr) {
|
|
|
|
return absl::string_view(contents_.data(), contents_.size());
|
|
|
|
} else {
|
|
|
|
absl::string_view already_flat_contents;
|
|
|
|
if (GetFlatAux(rep, &already_flat_contents)) {
|
|
|
|
return already_flat_contents;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FlattenSlowPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::Append(absl::string_view src) {
|
|
|
|
contents_.AppendArray(src, CordzUpdateTracker::kAppendString);
|
|
|
|
}
|
|
|
|
|
Export of internal Abseil changes
--
f49e405201d2ffd5955503fa8ad0f08ec0cdfb2b by Martijn Vels <mvels@google.com>:
Add common [container.requirements] type definitions to `CharRange` and `ChunkRange`
The presence of these allow these range classes to be used in various utility functions which require some minimum type of container. For example, this change allows tests to use `EXPECT_THAT(cord.Chunks(), ElementsAre(...))`
PiperOrigin-RevId: 406941278
--
0c195f073632e21d9a4bce158047b2ba8551c2d1 by Evan Brown <ezb@google.com>:
Use explicit exponential growth in SubstituteAndAppendArray.
PiperOrigin-RevId: 406931952
--
afb043bccd809a55cab78abadb7548a057d9eda0 by Jorg Brown <jorg@google.com>:
Use longer var names in macro to avoid clang-tidy warning
PiperOrigin-RevId: 406930978
--
80397e2604e6b3d929a34742c3a32581b34d3ac4 by Martijn Vels <mvels@google.com>:
Add future kAppendBuffer and kPrependBuffer API trackers for Cordz sampling
PiperOrigin-RevId: 406912759
--
e910ce919ef83933f08a690e8b7325c7cc5b6d5d by Martijn Vels <mvels@google.com>:
Implement Prepend(string_view) in terms of PrependArray(string_view, MethodIdentifier).
PiperOrigin-RevId: 406891665
--
c9cff43d4c0568ed01f2fca0f6ef038ae03112b5 by Martijn Vels <mvels@google.com>:
Add 'Rebuild' logic to CordRepBtree
There are btree hostile scenarios where an application could perform repeated split/insert/merge operations on a cord leading to a tree exceeding the maximum height. While this should be rare in practice, this change adds a Rebuild() method that will rebuild a tree with a 100% fill factor, and we will invoke this rebuild when a tree exceeds the maximum height. This basically follows the similar 'balance' logic in Concat trees (although the latter is common in Concat uses)
PiperOrigin-RevId: 406875739
--
5b2b8fb88f1ebfdc1c670088152da2cb2ea4c376 by Martijn Vels <mvels@google.com>:
Add 'in place' enabled RemoveSuffix
An in-place RemoveSuffix is more efficient than SubTree() as it can directly modify privately owned nodes and flats allowing easy re-use of free capacity in right-most flats that may turn into Substring edges when using SubTree.
PiperOrigin-RevId: 406431230
--
f09903c0a3d7344f59aaf1380a16ea10829217d4 by Derek Mauro <dmauro@google.com>:
Internal change
PiperOrigin-RevId: 406430373
--
9957af575c33bb18dc170572a4ee8cc5901df6b2 by Greg Falcon <gfalcon@google.com>:
Initial groundwork to allow storing checksum data inside CordRep instances.
This uses a RefcountAndFlags bit that was reserved for this purpose, and will be leveraged in a follow-up change to allow attaching checksums to a Cord's value.
This change splits RefcountAndFlags::IsOne() into two distinct operations:
* IsOne(): This returns true when the associated CordRep is not shared with other threads. This is useful for functions that consume CordRep instances; for example, code that consumes an unshared CordRep can assume ownership of its children without modifying those refcounts.
* IsMutable(): This returns true when the associated CordRep reference is not shared with other threads, *and* does not store an associated checksum value. This is useful for functions that modify a CordRep's contents: code may modify the bytes of a mutable-unshared CordRep without fear of races with other threads, or of invalidating a stored checksum.
The tricky part of this CL is ensuring that the correct choice between IsMutable() and IsOne() was made at each point. An incorrect application of IsOne() could lead to correctness bugs in the future. Code conditioned on IsOne() may delete the CordRep in question, or assume ownership of its children, but must not modify the CordRep's data without explicitly adjusting the CRC.
PiperOrigin-RevId: 406191103
--
686544814079e5ab6d4593cca0c068b510be400a by Martijn Vels <mvels@google.com>:
Reduce the size in the LargeString test when running with Sanitizers
PiperOrigin-RevId: 406186945
--
735b4490bdb695c35731f06ce4b8de14ce2be6ed by Alex Strelnikov <strel@google.com>:
Release absl::SimpleHexAtoi.
PiperOrigin-RevId: 406143188
GitOrigin-RevId: f49e405201d2ffd5955503fa8ad0f08ec0cdfb2b
Change-Id: Ic6527ac40fa03ea02ca813e8bb7868a219544de4
3 years ago
|
|
|
inline void Cord::Prepend(absl::string_view src) {
|
|
|
|
PrependArray(src, CordzUpdateTracker::kPrependString);
|
|
|
|
}
|
|
|
|
|
Export of internal Abseil changes
--
7d0468a6610ed85586d5c87fd65de8dac5118923 by Derek Mauro <dmauro@google.com>:
Import of CCTZ from GitHub.
PiperOrigin-RevId: 313226473
--
1131ef6d116f5ce7d46537a82f300ea06dcaaa53 by Gennadiy Rozental <rogeeff@google.com>:
Migrate internal interface to use mutable references.
PiperOrigin-RevId: 312931131
--
96225212a9f5fbd0b38c71fe65539164992c7c3b by Laramie Leavitt <lar@google.com>:
Remove random/internal/distributions.h
This file was something of an historical artifact. All of the related
code has either been removed or migraged, and so the only remaining type
belongs with uniform_helper.h, as it is used to infer the return type
of the absl::Uniform method in a few cases.
PiperOrigin-RevId: 312878173
--
6dcbd5be58ad425e08740ff64088373ee7fe4a72 by Mark Barolak <mbar@google.com>:
Release the StrFormat test case for Cords to open source.
PiperOrigin-RevId: 312707974
--
34484d18dfb63a0a7ad6e2aaeb570e33592968be by Abseil Team <absl-team@google.com>:
Let Cord::Cord(string&&), Cord::operator=(string&&),
Cord::Append(string&&), and Cord::Prepend(string&&) steal string data
and embed it into the Cord as a single external chunk, instead of
copying it into flat chunks (at most 4083-byte each).
Stealing string data is faster, but it creates a long chunk, which leads
to a higher more memory usage if its subcords are created and outlive
the whole Cord.
These functions revert to copying the data if any of the following
conditions holds:
- string size is at most kMaxBytesToCopy (511), to avoid the overhead
of an external chunk for short strings;
- less than half of string capacity is used, to avoid pinning to much
unused memory.
PiperOrigin-RevId: 312683785
GitOrigin-RevId: 7d0468a6610ed85586d5c87fd65de8dac5118923
Change-Id: If79b5a1dfe6d53a8ddddbc7da84338f11fc4cfa3
5 years ago
|
|
|
extern template void Cord::Append(std::string&& src);
|
|
|
|
extern template void Cord::Prepend(std::string&& src);
|
|
|
|
|
|
|
|
inline int Cord::Compare(const Cord& rhs) const {
|
|
|
|
if (!contents_.is_tree() && !rhs.contents_.is_tree()) {
|
|
|
|
return contents_.BitwiseCompare(rhs.contents_);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CompareImpl(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Does 'this' cord start/end with rhs
|
|
|
|
inline bool Cord::StartsWith(const Cord& rhs) const {
|
|
|
|
if (contents_.IsSame(rhs.contents_)) return true;
|
|
|
|
size_t rhs_size = rhs.size();
|
|
|
|
if (size() < rhs_size) return false;
|
|
|
|
return EqualsImpl(rhs, rhs_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Cord::StartsWith(absl::string_view rhs) const {
|
|
|
|
size_t rhs_size = rhs.size();
|
|
|
|
if (size() < rhs_size) return false;
|
|
|
|
return EqualsImpl(rhs, rhs_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::ChunkIterator::InitTree(cord_internal::CordRep* tree) {
|
Export of internal Abseil changes
--
83e4cdf03a4d702b30e69204060de09e462e23c6 by Greg Falcon <gfalcon@google.com>:
Revert the crc addition to RefcountAndFlags, and restore related comments to their original state.
In development, the implementation of SetExpectedCrc() changed, and there is no longer a need to track the CRC status in the refcount.
Since the distinction between IsOne() and IsMutable() is subtle *and unused*, removing it now can help avoid subtle bugs in the future. This distinction can always be added back later, if it proves necessary.
Keep the reserved bit for now; all it costs is one extra mask instruction in the refcount checks, and space for extra state in Cord is always hard to find.
PiperOrigin-RevId: 408647038
--
ee67585cf66954176615271f50f8b278119dd138 by Greg Falcon <gfalcon@google.com>:
Implement Cord::SetExpectedChecksum() and Cord::ExpectedChecksum().
SetExpectedChecksum() will store a uint32_t out-of-band alongside a Cord's data. This value persists through copies and assignments. Mutating operations on a Cord cause the value to be forgotten. ExpectedChecksum() retrieves the stored value, if present.
This API is intended for storing a CRC32C checksum alongside data, allowing checksums to be passed through dataflows and validated at the final step. However, this API is agnostic to the meaning of the stored value. No CRC32C validation is performed by these new APIs.
This implementation adds a new CordRep node, CordRepCrc. A CordRepCrc may (currently) only live at the top of a tree. This allows traversal logic to be agnostic to these nodes, instead putting the needed branches at the mutation level. This also implements the property requested from API review, that any mutation is guaranteed to permanently forget the stored CRC.
PiperOrigin-RevId: 408611221
--
a86f592402b37c854ebdc77d2b9b425451a7a675 by Martijn Vels <mvels@google.com>:
Move 'ExtractResult' into CordRep
The result of an extract operation is logically identical for any tree implementation, and having a single type makes 'tree independent' implementation in cord.cc more concise.
PiperOrigin-RevId: 408332408
--
baa7647e21db59a87f75af9cac62172ce38a0f71 by Abseil Team <absl-team@google.com>:
Replace usages of `assert` macros with `ABSL_HARDENING_ASSERT`.
PiperOrigin-RevId: 408272133
--
c7658133d8662c39fa5035fc93a364c7c3d327e0 by Martijn Vels <mvels@google.com>:
Add CordRepBtree::ExtractAppendBuffer
PiperOrigin-RevId: 407944179
--
5775100363b5890ebfe710fadebf040445eab991 by Martijn Vels <mvels@google.com>:
Add CordRepConcat::ExtractAppendBuffer
PiperOrigin-RevId: 407932968
--
9f520ba1600a93352c78f644a369c7c76195ee86 by Greg Falcon <gfalcon@google.com>:
Add cordz tracking for crc nodes.
This also adds a new kSetExpectedChecksum method to the list of tracked methods. This is presently unused but will be used soon.
PiperOrigin-RevId: 407884120
GitOrigin-RevId: 83e4cdf03a4d702b30e69204060de09e462e23c6
Change-Id: I134ace2d87215813eaa60a282996a33884676c06
3 years ago
|
|
|
tree = cord_internal::SkipCrcNode(tree);
|
|
|
|
if (tree->tag == cord_internal::BTREE) {
|
|
|
|
current_chunk_ = btree_reader_.Init(tree->btree());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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()) {
|
|
|
|
InitTree(cord->contents_.as_tree());
|
|
|
|
} else {
|
|
|
|
current_chunk_ =
|
|
|
|
absl::string_view(cord->contents_.data(), bytes_remaining_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::ChunkIterator& Cord::ChunkIterator::AdvanceBtree() {
|
|
|
|
current_chunk_ = btree_reader_.Next();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::ChunkIterator::AdvanceBytesBtree(size_t n) {
|
|
|
|
assert(n >= current_chunk_.size());
|
|
|
|
bytes_remaining_ -= n;
|
|
|
|
if (bytes_remaining_) {
|
|
|
|
if (n == current_chunk_.size()) {
|
|
|
|
current_chunk_ = btree_reader_.Next();
|
|
|
|
} else {
|
|
|
|
size_t offset = btree_reader_.length() - bytes_remaining_;
|
|
|
|
current_chunk_ = btree_reader_.Seek(offset);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
current_chunk_ = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::ChunkIterator& Cord::ChunkIterator::operator++() {
|
|
|
|
ABSL_HARDENING_ASSERT(bytes_remaining_ > 0 &&
|
|
|
|
"Attempted to iterate past `end()`");
|
|
|
|
assert(bytes_remaining_ >= current_chunk_.size());
|
|
|
|
bytes_remaining_ -= current_chunk_.size();
|
|
|
|
if (bytes_remaining_ > 0) {
|
|
|
|
return btree_reader_ ? AdvanceBtree() : AdvanceStack();
|
|
|
|
} else {
|
|
|
|
current_chunk_ = {};
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::ChunkIterator Cord::ChunkIterator::operator++(int) {
|
|
|
|
ChunkIterator tmp(*this);
|
|
|
|
operator++();
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Cord::ChunkIterator::operator==(const ChunkIterator& other) const {
|
|
|
|
return bytes_remaining_ == other.bytes_remaining_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Cord::ChunkIterator::operator!=(const ChunkIterator& other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::ChunkIterator::reference Cord::ChunkIterator::operator*() const {
|
|
|
|
ABSL_HARDENING_ASSERT(bytes_remaining_ != 0);
|
|
|
|
return current_chunk_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::ChunkIterator::pointer Cord::ChunkIterator::operator->() const {
|
|
|
|
ABSL_HARDENING_ASSERT(bytes_remaining_ != 0);
|
|
|
|
return ¤t_chunk_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::ChunkIterator::RemoveChunkPrefix(size_t n) {
|
|
|
|
assert(n < current_chunk_.size());
|
|
|
|
current_chunk_.remove_prefix(n);
|
|
|
|
bytes_remaining_ -= 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) {
|
|
|
|
btree_reader_ ? AdvanceBytesBtree(n) : AdvanceBytesSlowPath(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::ChunkIterator Cord::chunk_begin() const {
|
|
|
|
return ChunkIterator(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::ChunkIterator Cord::chunk_end() const { return ChunkIterator(); }
|
|
|
|
|
|
|
|
inline Cord::ChunkIterator Cord::ChunkRange::begin() const {
|
|
|
|
return cord_->chunk_begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::ChunkIterator Cord::ChunkRange::end() const {
|
|
|
|
return cord_->chunk_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::ChunkRange Cord::Chunks() const { return ChunkRange(this); }
|
|
|
|
|
|
|
|
inline Cord::CharIterator& Cord::CharIterator::operator++() {
|
|
|
|
if (ABSL_PREDICT_TRUE(chunk_iterator_->size() > 1)) {
|
|
|
|
chunk_iterator_.RemoveChunkPrefix(1);
|
|
|
|
} else {
|
|
|
|
++chunk_iterator_;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::CharIterator Cord::CharIterator::operator++(int) {
|
|
|
|
CharIterator tmp(*this);
|
|
|
|
operator++();
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Cord::CharIterator::operator==(const CharIterator& other) const {
|
|
|
|
return chunk_iterator_ == other.chunk_iterator_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool Cord::CharIterator::operator!=(const CharIterator& other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::CharIterator::reference Cord::CharIterator::operator*() const {
|
|
|
|
return *chunk_iterator_->data();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::CharIterator::pointer Cord::CharIterator::operator->() const {
|
|
|
|
return chunk_iterator_->data();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord Cord::AdvanceAndRead(CharIterator* it, size_t n_bytes) {
|
|
|
|
assert(it != nullptr);
|
|
|
|
return it->chunk_iterator_.AdvanceAndReadBytes(n_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Cord::Advance(CharIterator* it, size_t n_bytes) {
|
|
|
|
assert(it != nullptr);
|
|
|
|
it->chunk_iterator_.AdvanceBytes(n_bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline absl::string_view Cord::ChunkRemaining(const CharIterator& it) {
|
|
|
|
return *it.chunk_iterator_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::CharIterator Cord::char_begin() const {
|
|
|
|
return CharIterator(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::CharIterator Cord::char_end() const { return CharIterator(); }
|
|
|
|
|
|
|
|
inline Cord::CharIterator Cord::CharRange::begin() const {
|
|
|
|
return cord_->char_begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::CharIterator Cord::CharRange::end() const {
|
|
|
|
return cord_->char_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Cord::CharRange Cord::Chars() const { return CharRange(this); }
|
|
|
|
|
|
|
|
inline void Cord::ForEachChunk(
|
|
|
|
absl::FunctionRef<void(absl::string_view)> callback) const {
|
|
|
|
absl::cord_internal::CordRep* rep = contents_.tree();
|
|
|
|
if (rep == nullptr) {
|
|
|
|
callback(absl::string_view(contents_.data(), contents_.size()));
|
|
|
|
} else {
|
|
|
|
return ForEachChunkAux(rep, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nonmember Cord-to-Cord relational operarators.
|
|
|
|
inline bool operator==(const Cord& lhs, const Cord& rhs) {
|
|
|
|
if (lhs.contents_.IsSame(rhs.contents_)) return true;
|
|
|
|
size_t rhs_size = rhs.size();
|
|
|
|
if (lhs.size() != rhs_size) return false;
|
|
|
|
return lhs.EqualsImpl(rhs, rhs_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator!=(const Cord& x, const Cord& y) { return !(x == y); }
|
|
|
|
inline bool operator<(const Cord& x, const Cord& y) { return x.Compare(y) < 0; }
|
|
|
|
inline bool operator>(const Cord& x, const Cord& y) { return x.Compare(y) > 0; }
|
|
|
|
inline bool operator<=(const Cord& x, const Cord& y) {
|
|
|
|
return x.Compare(y) <= 0;
|
|
|
|
}
|
|
|
|
inline bool operator>=(const Cord& x, const Cord& y) {
|
|
|
|
return x.Compare(y) >= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nonmember Cord-to-absl::string_view relational operators.
|
|
|
|
//
|
|
|
|
// Due to implicit conversions, these also enable comparisons of Cord with
|
|
|
|
// with std::string, ::string, and const char*.
|
|
|
|
inline bool operator==(const Cord& lhs, absl::string_view rhs) {
|
|
|
|
size_t lhs_size = lhs.size();
|
|
|
|
size_t rhs_size = rhs.size();
|
|
|
|
if (lhs_size != rhs_size) return false;
|
|
|
|
return lhs.EqualsImpl(rhs, rhs_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator==(absl::string_view x, const Cord& y) { return y == x; }
|
|
|
|
inline bool operator!=(const Cord& x, absl::string_view y) { return !(x == y); }
|
|
|
|
inline bool operator!=(absl::string_view x, const Cord& y) { return !(x == y); }
|
|
|
|
inline bool operator<(const Cord& x, absl::string_view y) {
|
|
|
|
return x.Compare(y) < 0;
|
|
|
|
}
|
|
|
|
inline bool operator<(absl::string_view x, const Cord& y) {
|
|
|
|
return y.Compare(x) > 0;
|
|
|
|
}
|
|
|
|
inline bool operator>(const Cord& x, absl::string_view y) { return y < x; }
|
|
|
|
inline bool operator>(absl::string_view x, const Cord& y) { return y < x; }
|
|
|
|
inline bool operator<=(const Cord& x, absl::string_view y) { return !(y < x); }
|
|
|
|
inline bool operator<=(absl::string_view x, const Cord& y) { return !(y < x); }
|
|
|
|
inline bool operator>=(const Cord& x, absl::string_view y) { return !(x < y); }
|
|
|
|
inline bool operator>=(absl::string_view x, const Cord& y) { return !(x < y); }
|
|
|
|
|
|
|
|
// Some internals exposed to test code.
|
|
|
|
namespace strings_internal {
|
|
|
|
class CordTestAccess {
|
|
|
|
public:
|
|
|
|
static size_t FlatOverhead();
|
|
|
|
static size_t MaxFlatLength();
|
|
|
|
static size_t SizeofCordRepConcat();
|
|
|
|
static size_t SizeofCordRepExternal();
|
|
|
|
static size_t SizeofCordRepSubstring();
|
|
|
|
static size_t FlatTagToLength(uint8_t tag);
|
|
|
|
static uint8_t LengthToTag(size_t s);
|
|
|
|
};
|
|
|
|
} // namespace strings_internal
|
|
|
|
ABSL_NAMESPACE_END
|
|
|
|
} // namespace absl
|
|
|
|
|
|
|
|
#endif // ABSL_STRINGS_CORD_H_
|