Export of internal Abseil changes
-- 44ccc0320ffaa2106ba3c6393b5a40c3b4f7b901 by Abseil Team <absl-team@google.com>: Clarify span iterator documentation. PiperOrigin-RevId: 299110584 -- 80d016d8026b8d6904aa0ff2d5e1c3ae27f129bb by Greg Falcon <gfalcon@google.com>: Add Cord::TryFlat(). PiperOrigin-RevId: 298889772 -- da6900203f1e4131d5693cbca157b6dba099bbed by Greg Falcon <gfalcon@google.com>: clang-format cord_test.cc. PiperOrigin-RevId: 298851425 GitOrigin-RevId: 44ccc0320ffaa2106ba3c6393b5a40c3b4f7b901 Change-Id: Ia5394f6fbb473d206726fdd48a00eb07a6acad6a
This commit is contained in:
parent
b19ba96766
commit
cf3a1998e9
5 changed files with 101 additions and 25 deletions
|
|
@ -53,6 +53,7 @@
|
|||
#include "absl/strings/internal/cord_internal.h"
|
||||
#include "absl/strings/internal/resize_uninitialized.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/optional.h"
|
||||
|
||||
namespace absl {
|
||||
ABSL_NAMESPACE_BEGIN
|
||||
|
|
@ -512,6 +513,10 @@ class Cord {
|
|||
// REQUIRES: 0 <= i < size()
|
||||
char operator[](size_t i) const;
|
||||
|
||||
// If this cord's representation is a single flat array, return a
|
||||
// string_view referencing that array. Otherwise return nullopt.
|
||||
absl::optional<absl::string_view> TryFlat() const;
|
||||
|
||||
// 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.
|
||||
|
|
@ -630,7 +635,7 @@ class Cord {
|
|||
// Helper for MemoryUsage()
|
||||
static size_t MemoryUsageAux(const absl::cord_internal::CordRep* rep);
|
||||
|
||||
// Helper for GetFlat()
|
||||
// Helper for GetFlat() and TryFlat()
|
||||
static bool GetFlatAux(absl::cord_internal::CordRep* rep,
|
||||
absl::string_view* fragment);
|
||||
|
||||
|
|
@ -942,6 +947,18 @@ inline size_t Cord::EstimatedMemoryUsage() const {
|
|||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue