Commit d61843e5 by Abseil Team Committed by vslashg

Export of internal Abseil changes

--
b20c539b8e21fee7d4d908a8a26a317a3de9d993 by Martijn Vels <mvels@google.com>:

Add CordRepBtree implementation

PiperOrigin-RevId: 385679196

--
96f7753b7af5fd964537d5794dd597bb6e698071 by Derek Mauro <dmauro@google.com>:

Update Abseil dependencies

PiperOrigin-RevId: 385643956

--
67bdae4c686f0df09cc7155633c03218bf23d177 by Abseil Team <absl-team@google.com>:

Fix up some small typos in error messages.

PiperOrigin-RevId: 385625107
GitOrigin-RevId: b20c539b8e21fee7d4d908a8a26a317a3de9d993
Change-Id: I8f602cfe9f7878b0558359ab15efb048caefb3a5
parent 33541e75
......@@ -205,6 +205,8 @@ set(ABSL_INTERNAL_DLL_FILES
"strings/internal/cord_internal.h"
"strings/internal/cord_rep_consume.h"
"strings/internal/cord_rep_consume.cc"
"strings/internal/cord_rep_btree.cc"
"strings/internal/cord_rep_btree.h"
"strings/internal/cord_rep_flat.h"
"strings/internal/cord_rep_ring.cc"
"strings/internal/cord_rep_ring.h"
......
......@@ -15,29 +15,30 @@
#
workspace(name = "com_google_absl")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# GoogleTest/GoogleMock framework. Used by most unit-tests.
http_archive(
name = "com_google_googletest",
name = "com_google_googletest", # 2021-07-09T13:28:13Z
sha256 = "12ef65654dc01ab40f6f33f9d02c04f2097d2cd9fbe48dc6001b29543583b0ad",
strip_prefix = "googletest-8d51ffdfab10b3fba636ae69bc03da4b54f8c235",
# Keep this URL in sync with ABSL_GOOGLETEST_COMMIT in ci/cmake_common.sh.
urls = ["https://github.com/google/googletest/archive/5bcd8e3bb929714e031a542d303f818e5a5af45d.zip"], # 2021-06-08T22:36:38Z
strip_prefix = "googletest-5bcd8e3bb929714e031a542d303f818e5a5af45d",
sha256 = "3adecb6686ac7367452561dca518fad5a990fb09c5a961bfa1836f15eb774348",
urls = ["https://github.com/google/googletest/archive/8d51ffdfab10b3fba636ae69bc03da4b54f8c235.zip"],
)
# Google benchmark.
http_archive(
name = "com_github_google_benchmark",
urls = ["https://github.com/google/benchmark/archive/7d0d9061d83b663ce05d9de5da3d5865a3845b79.zip"], # 2021-05-11T11:56:00Z
strip_prefix = "benchmark-7d0d9061d83b663ce05d9de5da3d5865a3845b79",
sha256 = "a07789754963e3ea3a1e13fed3a4d48fac0c5f7f749c5065f6c30cd2c1529661",
name = "com_github_google_benchmark", # 2021-07-01T09:02:54Z
sha256 = "1cb4b97a90aa1fd9c8e412a6bc29fc13fc140162a4a0db3811af40befd8c9ea5",
strip_prefix = "benchmark-e451e50e9b8af453f076dec10bd6890847f1624e",
urls = ["https://github.com/google/benchmark/archive/e451e50e9b8af453f076dec10bd6890847f1624e.zip"],
)
# C++ rules for Bazel.
http_archive(
name = "rules_cc",
urls = ["https://github.com/bazelbuild/rules_cc/archive/ab5395627c80e025e824bd005d41f96b20618b9d.zip"], # 2021-05-10T15:35:04Z
strip_prefix = "rules_cc-ab5395627c80e025e824bd005d41f96b20618b9d",
sha256 = "f3908cb40a6577ab0d1ef9e00052739bf69b4313fa7d20b4d61d4521ea67abf3",
name = "rules_cc", # 2021-06-07T16:41:49Z
sha256 = "b295cad8c5899e371dde175079c0a2cdc0151f5127acc92366a8c986beb95c76",
strip_prefix = "rules_cc-daf6ace7cfeacd6a83e9ff2ed659f416537b6c74",
urls = ["https://github.com/bazelbuild/rules_cc/archive/daf6ace7cfeacd6a83e9ff2ed659f416537b6c74.zip"],
)
......@@ -188,25 +188,25 @@ void ClearCurrentThreadIdentity();
// May be chosen at compile time via: -DABSL_FORCE_THREAD_IDENTITY_MODE=<mode
// index>
#ifdef ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC
#error ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC cannot be direcly set
#error ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC cannot be directly set
#else
#define ABSL_THREAD_IDENTITY_MODE_USE_POSIX_SETSPECIFIC 0
#endif
#ifdef ABSL_THREAD_IDENTITY_MODE_USE_TLS
#error ABSL_THREAD_IDENTITY_MODE_USE_TLS cannot be direcly set
#error ABSL_THREAD_IDENTITY_MODE_USE_TLS cannot be directly set
#else
#define ABSL_THREAD_IDENTITY_MODE_USE_TLS 1
#endif
#ifdef ABSL_THREAD_IDENTITY_MODE_USE_CPP11
#error ABSL_THREAD_IDENTITY_MODE_USE_CPP11 cannot be direcly set
#error ABSL_THREAD_IDENTITY_MODE_USE_CPP11 cannot be directly set
#else
#define ABSL_THREAD_IDENTITY_MODE_USE_CPP11 2
#endif
#ifdef ABSL_THREAD_IDENTITY_MODE
#error ABSL_THREAD_IDENTITY_MODE cannot be direcly set
#error ABSL_THREAD_IDENTITY_MODE cannot be directly set
#elif defined(ABSL_FORCE_THREAD_IDENTITY_MODE)
#define ABSL_THREAD_IDENTITY_MODE ABSL_FORCE_THREAD_IDENTITY_MODE
#elif defined(_WIN32) && !defined(__MINGW32__)
......
......@@ -269,11 +269,13 @@ cc_library(
name = "cord_internal",
srcs = [
"internal/cord_internal.cc",
"internal/cord_rep_btree.cc",
"internal/cord_rep_consume.cc",
"internal/cord_rep_ring.cc",
],
hdrs = [
"internal/cord_internal.h",
"internal/cord_rep_btree.h",
"internal/cord_rep_consume.h",
"internal/cord_rep_flat.h",
"internal/cord_rep_ring.h",
......@@ -296,6 +298,23 @@ cc_library(
"//absl/container:layout",
"//absl/functional:function_ref",
"//absl/meta:type_traits",
"//absl/types:span",
],
)
cc_test(
name = "cord_rep_btree_test",
size = "medium",
srcs = ["internal/cord_rep_btree_test.cc"],
copts = ABSL_TEST_COPTS,
visibility = ["//visibility:private"],
deps = [
":cord_internal",
":cord_rep_test_util",
":strings",
"//absl/base:config",
"//absl/base:raw_logging_internal",
"@com_google_googletest//:gtest_main",
],
)
......@@ -578,6 +597,19 @@ cc_library(
)
cc_library(
name = "cord_rep_test_util",
testonly = 1,
hdrs = ["internal/cord_rep_test_util.h"],
copts = ABSL_DEFAULT_COPTS,
deps = [
":cord_internal",
":strings",
"//absl/base:config",
"//absl/base:raw_logging_internal",
],
)
cc_library(
name = "cordz_test_helpers",
testonly = 1,
hdrs = ["cordz_test_helpers.h"],
......
......@@ -555,12 +555,14 @@ absl_cc_library(
cord_internal
HDRS
"internal/cord_internal.h"
"internal/cord_rep_btree.h"
"internal/cord_rep_consume.h"
"internal/cord_rep_flat.h"
"internal/cord_rep_ring.h"
"internal/cord_rep_ring_reader.h"
SRCS
"internal/cord_internal.cc"
"internal/cord_rep_btree.cc"
"internal/cord_rep_consume.cc"
"internal/cord_rep_ring.cc"
COPTS
......@@ -849,6 +851,21 @@ absl_cc_library(
absl_cc_library(
NAME
cord_rep_test_util
HDRS
"internal/cord_rep_test_util.h"
COPTS
${ABSL_TEST_COPTS}
DEPS
absl::config
absl::cord_internal
absl::raw_logging_internal
absl::strings
TESTONLY
)
absl_cc_library(
NAME
cord_test_helpers
HDRS
"cord_test_helpers.h"
......@@ -924,6 +941,24 @@ absl_cc_test(
absl_cc_test(
NAME
cord_rep_btree_test
SRCS
"internal/cord_rep_btree_test.cc"
COPTS
${ABSL_TEST_COPTS}
DEPS
absl::base
absl::config
absl::cord_internal
absl::cord_rep_test_util
absl::core_headers
absl::raw_logging_internal
absl::strings
GTest::gmock_main
)
absl_cc_test(
NAME
cord_ring_test
SRCS
"cord_ring_test.cc"
......
......@@ -18,6 +18,7 @@
#include <memory>
#include "absl/container/inlined_vector.h"
#include "absl/strings/internal/cord_rep_btree.h"
#include "absl/strings/internal/cord_rep_flat.h"
#include "absl/strings/internal/cord_rep_ring.h"
......@@ -50,6 +51,9 @@ void CordRep::Destroy(CordRep* rep) {
rep = left;
continue;
}
} else if (rep->tag == BTREE) {
CordRepBtree::Destroy(rep->btree());
rep = nullptr;
} else if (rep->tag == RING) {
CordRepRing::Destroy(rep->ring());
rep = nullptr;
......
// Copyright 2021 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.
#ifndef ABSL_STRINGS_INTERNAL_CORD_REP_TEST_UTIL_H_
#define ABSL_STRINGS_INTERNAL_CORD_REP_TEST_UTIL_H_
#include <cassert>
#include <memory>
#include <random>
#include <string>
#include <vector>
#include "absl/base/config.h"
#include "absl/base/internal/raw_logging.h"
#include "absl/strings/internal/cord_internal.h"
#include "absl/strings/internal/cord_rep_btree.h"
#include "absl/strings/internal/cord_rep_flat.h"
#include "absl/strings/string_view.h"
namespace absl {
ABSL_NAMESPACE_BEGIN
namespace cordrep_testing {
inline cord_internal::CordRepSubstring* MakeSubstring(
size_t start, size_t len, cord_internal::CordRep* rep) {
auto* sub = new cord_internal::CordRepSubstring;
sub->tag = cord_internal::SUBSTRING;
sub->start = start;
sub->length = len <= 0 ? rep->length - start + len : len;
sub->child = rep;
return sub;
}
inline cord_internal::CordRepConcat* MakeConcat(cord_internal::CordRep* left,
cord_internal::CordRep* right,
int depth = 0) {
auto* concat = new cord_internal::CordRepConcat;
concat->tag = cord_internal::CONCAT;
concat->length = left->length + right->length;
concat->left = left;
concat->right = right;
concat->set_depth(depth);
return concat;
}
inline cord_internal::CordRepFlat* MakeFlat(absl::string_view value) {
assert(value.length() <= cord_internal::kMaxFlatLength);
auto* flat = cord_internal::CordRepFlat::New(value.length());
flat->length = value.length();
memcpy(flat->Data(), value.data(), value.length());
return flat;
}
// Creates an external node for testing
inline cord_internal::CordRepExternal* MakeExternal(absl::string_view s) {
struct Rep : public cord_internal::CordRepExternal {
std::string s;
explicit Rep(absl::string_view sv) : s(sv) {
this->tag = cord_internal::EXTERNAL;
this->base = s.data();
this->length = s.length();
this->releaser_invoker = [](cord_internal::CordRepExternal* self) {
delete static_cast<Rep*>(self);
};
}
};
return new Rep(s);
}
inline std::string CreateRandomString(size_t n) {
absl::string_view data =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789~!@#$%^&*()_+=-<>?:\"{}[]|";
std::minstd_rand rnd;
std::uniform_int_distribution<size_t> dist(0, data.size() - 1);
std::string s(n, ' ');
for (size_t i = 0; i < n; ++i) {
s[i] = data[dist(rnd)];
}
return s;
}
// Creates an array of flats from the provided string, chopping
// the provided string up into flats of size `chunk_size` characters
// resulting in roughly `data.size() / chunk_size` total flats.
inline std::vector<cord_internal::CordRep*> CreateFlatsFromString(
absl::string_view data, size_t chunk_size) {
assert(chunk_size > 0);
std::vector<cord_internal::CordRep*> flats;
for (absl::string_view s = data; !s.empty(); s.remove_prefix(chunk_size)) {
flats.push_back(MakeFlat(s.substr(0, chunk_size)));
}
return flats;
}
inline cord_internal::CordRepBtree* CordRepBtreeFromFlats(
absl::Span<cord_internal::CordRep* const> flats) {
assert(!flats.empty());
auto* node = cord_internal::CordRepBtree::Create(flats[0]);
for (size_t i = 1; i < flats.size(); ++i) {
node = cord_internal::CordRepBtree::Append(node, flats[i]);
}
return node;
}
inline void CordToString(cord_internal::CordRep* rep, std::string& s) {
size_t offset = 0;
size_t length = rep->length;
while (rep->tag == cord_internal::SUBSTRING) {
offset += rep->substring()->start;
rep = rep->substring()->child;
}
if (rep->tag == cord_internal::BTREE) {
for (cord_internal::CordRep* edge : rep->btree()->Edges()) {
CordToString(edge, s);
}
} else if (rep->tag >= cord_internal::FLAT) {
s.append(rep->flat()->Data() + offset, length);
} else if (rep->tag == cord_internal::EXTERNAL) {
s.append(rep->external()->base + offset, length);
} else {
ABSL_RAW_LOG(FATAL, "Unsupported tag %d", rep->tag);
}
}
inline std::string CordToString(cord_internal::CordRep* rep) {
std::string s;
s.reserve(rep->length);
CordToString(rep, s);
return s;
}
// RAII Helper class to automatically unref reps on destruction.
class AutoUnref {
public:
~AutoUnref() {
for (CordRep* rep : unrefs_) CordRep::Unref(rep);
}
// Adds `rep` to the list of reps to be unreffed at destruction.
template <typename CordRepType>
CordRepType* Add(CordRepType* rep) {
unrefs_.push_back(rep);
return rep;
}
// Increments the reference count of `rep` by one, and adds it to
// the list of reps to be unreffed at destruction.
template <typename CordRepType>
CordRepType* Ref(CordRepType* rep) {
unrefs_.push_back(CordRep::Ref(rep));
return rep;
}
// Increments the reference count of `rep` by one if `condition` is true,
// and adds it to the list of reps to be unreffed at destruction.
template <typename CordRepType>
CordRepType* RefIf(bool condition, CordRepType* rep) {
if (condition) unrefs_.push_back(CordRep::Ref(rep));
return rep;
}
private:
using CordRep = absl::cord_internal::CordRep;
std::vector<CordRep*> unrefs_;
};
} // namespace cordrep_testing
ABSL_NAMESPACE_END
} // namespace absl
#endif // ABSL_STRINGS_INTERNAL_CORD_REP_TEST_UTIL_H_
......@@ -14,7 +14,7 @@
# The commit of GoogleTest to be used in the CMake tests in this directory.
# Keep this in sync with the commit in the WORKSPACE file.
readonly ABSL_GOOGLETEST_COMMIT="5bcd8e3bb929714e031a542d303f818e5a5af45d"
readonly ABSL_GOOGLETEST_COMMIT="8d51ffdfab10b3fba636ae69bc03da4b54f8c235"
# Avoid depending on GitHub by looking for a cached copy of the commit first.
if [[ -r "${KOKORO_GFILE_DIR:-}/distdir/${ABSL_GOOGLETEST_COMMIT}.zip" ]]; then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment