Skip to content

Commit

Permalink
Export of internal Abseil changes
Browse files Browse the repository at this point in the history
--
262f6992ee0553782531ad58dd7d8bcd6d0b7bb7 by Martijn Vels <mvels@google.com>:

Remove CordRepConcat uses in tests and CONCAT constants.

This change removes the creation and uses of CordRepConcat in unit tests, and replaces some remaining CONCAT constants with IsConcat() to make subsequent teardown of CordrepConcat uses easier.

PiperOrigin-RevId: 426932694

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

Replace NULL and 0 with nullptr.

PiperOrigin-RevId: 426912932

--
183e5babc478748023f732a1608745a2a544c996 by Abseil Team <absl-team@google.com>:

Replace "span of time" with "amount of time" in the first comment line, to make it clearer that we're not talking about a duration that starts at a specific time.

PiperOrigin-RevId: 426691794

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

Add extra assertions on CordRepSubstring child nodes

PiperOrigin-RevId: 426369104
GitOrigin-RevId: 262f6992ee0553782531ad58dd7d8bcd6d0b7bb7
Change-Id: I7ffdaa2dc999a2117944c9abdb1565b6b6f48b59
  • Loading branch information
Abseil Team authored and suertreus committed Feb 7, 2022
1 parent 36db0e4 commit 73316fc
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 592 deletions.
11 changes: 5 additions & 6 deletions absl/base/internal/low_level_alloc_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static void Test(bool use_new_arena, bool call_malloc_hook, int n) {
AllocMap::iterator it;
BlockDesc block_desc;
int rnd;
LowLevelAlloc::Arena *arena = 0;
LowLevelAlloc::Arena *arena = nullptr;
if (use_new_arena) {
int32_t flags = call_malloc_hook ? LowLevelAlloc::kCallMallocHook : 0;
arena = LowLevelAlloc::NewArena(flags);
Expand All @@ -101,11 +101,10 @@ static void Test(bool use_new_arena, bool call_malloc_hook, int n) {
case 0: // coin came up heads: add a block
using_low_level_alloc = true;
block_desc.len = rand() & 0x3fff;
block_desc.ptr =
reinterpret_cast<char *>(
arena == 0
? LowLevelAlloc::Alloc(block_desc.len)
: LowLevelAlloc::AllocWithArena(block_desc.len, arena));
block_desc.ptr = reinterpret_cast<char *>(
arena == nullptr
? LowLevelAlloc::Alloc(block_desc.len)
: LowLevelAlloc::AllocWithArena(block_desc.len, arena));
using_low_level_alloc = false;
RandomizeBlockDesc(&block_desc);
rnd = rand();
Expand Down
30 changes: 0 additions & 30 deletions absl/strings/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,6 @@ cc_library(
],
)

cc_test(
name = "cord_rep_concat_test",
size = "small",
srcs = ["internal/cord_rep_concat_test.cc"],
copts = ABSL_TEST_COPTS,
visibility = ["//visibility:private"],
deps = [
":cord_internal",
":cord_rep_test_util",
"//absl/base:config",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "cord_rep_btree_test",
size = "medium",
Expand Down Expand Up @@ -758,22 +744,6 @@ cc_test(
],
)

cc_test(
name = "cord_rep_consume_test",
size = "medium",
srcs = ["internal/cord_rep_consume_test.cc"],
copts = ABSL_TEST_COPTS,
visibility = ["//visibility:private"],
deps = [
":cord_internal",
":strings",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/debugging:leak_check",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "cord_ring_test",
size = "medium",
Expand Down
34 changes: 0 additions & 34 deletions absl/strings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -933,40 +933,6 @@ absl_cc_test(
GTest::gmock_main
)

absl_cc_test(
NAME
cord_rep_consume_test
SRCS
"internal/cord_rep_consume_test.cc"
COPTS
${ABSL_TEST_COPTS}
DEPS
absl::base
absl::config
absl::cord_internal
absl::core_headers
absl::function_ref
absl::raw_logging_internal
absl::strings
GTest::gmock_main
)

absl_cc_test(
NAME
cord_rep_concat_test
SRCS
"internal/cord_rep_concat_test.cc"
COPTS
${ABSL_TEST_COPTS}
DEPS
absl::base
absl::config
absl::cord_internal
absl::cord_rep_test_util
absl::core_headers
GTest::gmock_main
)

absl_cc_test(
NAME
cord_rep_btree_test
Expand Down
2 changes: 1 addition & 1 deletion absl/strings/cord_analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ size_t GetEstimatedUsage(const CordRep* rep) {
AnalyzeDataEdge(repref, raw_usage);
} else if (repref.rep->tag == BTREE) {
AnalyzeBtree(repref, raw_usage);
} else if (repref.rep->tag == CONCAT) {
} else if (repref.rep->IsConcat()) {
AnalyzeConcat(repref, raw_usage);
} else if (repref.rep->tag == RING) {
AnalyzeRing(repref, raw_usage);
Expand Down
41 changes: 0 additions & 41 deletions absl/strings/cord_ring_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ using ::absl::cord_internal::CordRepFlat;
using ::absl::cord_internal::CordRepRing;
using ::absl::cord_internal::CordRepSubstring;

using ::absl::cord_internal::CONCAT;
using ::absl::cord_internal::EXTERNAL;
using ::absl::cord_internal::SUBSTRING;

Expand Down Expand Up @@ -262,16 +261,6 @@ CordRepSubstring* RemoveSuffix(size_t length, CordRep* rep) {
return MakeSubstring(0, rep->length - length, rep);
}

CordRepConcat* MakeConcat(CordRep* left, CordRep* right, int depth = 0) {
auto* concat = new CordRepConcat;
concat->tag = CONCAT;
concat->length = left->length + right->length;
concat->left = left;
concat->right = right;
concat->set_depth(depth);
return concat;
}

enum Composition { kMix, kAppend, kPrepend };

Composition RandomComposition() {
Expand All @@ -296,7 +285,6 @@ constexpr const char* kFox = "The quick brown fox jumps over the lazy dog";
constexpr const char* kFoxFlats[] = {"The ", "quick ", "brown ",
"fox ", "jumps ", "over ",
"the ", "lazy ", "dog"};
constexpr const char* kAlphabet = "abcdefghijklmnopqrstuvwxyz";

CordRepRing* FromFlats(Span<const char* const> flats,
Composition composition = kAppend) {
Expand Down Expand Up @@ -594,35 +582,6 @@ TEST_P(CordRingCreateFromTreeTest, CreateFromSubstringOfLargeExternal) {
EXPECT_THAT(ToRawFlats(result), ElementsAre(str));
}

TEST_P(CordRingBuildInputTest, CreateFromConcat) {
CordRep* flats[] = {MakeFlat("abcdefgh"), MakeFlat("ijklm"),
MakeFlat("nopqrstuv"), MakeFlat("wxyz")};
auto* left = MakeConcat(RefIfInputSharedIndirect(flats[0]), flats[1]);
auto* right = MakeConcat(flats[2], RefIfInputSharedIndirect(flats[3]));
auto* concat = RefIfInputShared(MakeConcat(left, right));
CordRepRing* result = NeedsUnref(CordRepRing::Create(concat));
ASSERT_THAT(result, IsValidRingBuffer());
EXPECT_THAT(result->length, Eq(26));
EXPECT_THAT(ToString(result), Eq(kAlphabet));
}

TEST_P(CordRingBuildInputTest, CreateFromSubstringConcat) {
for (size_t off = 0; off < 26; ++off) {
for (size_t len = 1; len < 26 - off; ++len) {
CordRep* flats[] = {MakeFlat("abcdefgh"), MakeFlat("ijklm"),
MakeFlat("nopqrstuv"), MakeFlat("wxyz")};
auto* left = MakeConcat(RefIfInputSharedIndirect(flats[0]), flats[1]);
auto* right = MakeConcat(flats[2], RefIfInputSharedIndirect(flats[3]));
auto* concat = MakeConcat(left, right);
auto* child = RefIfInputShared(MakeSubstring(off, len, concat));
CordRepRing* result = NeedsUnref(CordRepRing::Create(child));
ASSERT_THAT(result, IsValidRingBuffer());
ASSERT_THAT(result->length, Eq(len));
ASSERT_THAT(ToString(result), string_view(kAlphabet).substr(off, len));
}
}
}

TEST_P(CordRingCreateTest, Properties) {
absl::string_view str1 = "abcdefghijklmnopqrstuvwxyz";
CordRepRing* result = NeedsUnref(CordRepRing::Create(MakeFlat(str1), 120));
Expand Down
2 changes: 1 addition & 1 deletion absl/strings/internal/cord_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void CordRep::Destroy(CordRep* rep) {
absl::InlinedVector<CordRep*, Constants::kInlinedVectorSize> pending;
while (true) {
assert(!rep->refcount.IsImmortal());
if (rep->tag == CONCAT) {
if (rep->IsConcat()) {
CordRepConcat* rep_concat = rep->concat();
CordRep* right = rep_concat->right;
if (!right->refcount.Decrement()) {
Expand Down
1 change: 1 addition & 0 deletions absl/strings/internal/cord_rep_btree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ CordRepSubstring* CreateSubstring(CordRep* rep, size_t offset, size_t n) {
rep = CordRep::Ref(substring->child);
CordRep::Unref(substring);
}
assert(rep->IsExternal() || rep->IsFlat());
CordRepSubstring* substring = new CordRepSubstring();
substring->length = n;
substring->tag = SUBSTRING;
Expand Down
1 change: 1 addition & 0 deletions absl/strings/internal/cord_rep_btree_navigator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ inline CordRep* Substring(CordRep* rep, size_t offset, size_t n) {
rep = rep->substring()->child;
}

assert(rep->IsExternal() || rep->IsFlat());
CordRepSubstring* substring = new CordRepSubstring();
substring->length = n;
substring->tag = SUBSTRING;
Expand Down
50 changes: 0 additions & 50 deletions absl/strings/internal/cord_rep_btree_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ using ::absl::cordrep_testing::CordToString;
using ::absl::cordrep_testing::CordVisitReps;
using ::absl::cordrep_testing::CreateFlatsFromString;
using ::absl::cordrep_testing::CreateRandomString;
using ::absl::cordrep_testing::MakeConcat;
using ::absl::cordrep_testing::MakeExternal;
using ::absl::cordrep_testing::MakeFlat;
using ::absl::cordrep_testing::MakeSubstring;
Expand Down Expand Up @@ -322,7 +321,6 @@ TEST(CordRepBtreeTest, EdgeData) {
CordRepExternal* external = MakeExternal("Hello external");
CordRep* substr1 = MakeSubstring(1, 6, CordRep::Ref(flat));
CordRep* substr2 = MakeSubstring(1, 6, CordRep::Ref(external));
CordRep* concat = MakeConcat(CordRep::Ref(flat), CordRep::Ref(external));
CordRep* bad_substr = MakeSubstring(1, 2, CordRep::Ref(substr1));

EXPECT_TRUE(CordRepBtree::IsDataEdge(flat));
Expand All @@ -345,17 +343,13 @@ TEST(CordRepBtreeTest, EdgeData) {
TypedEq<const void*>(external->base + 1));
EXPECT_THAT(CordRepBtree::EdgeData(substr2), Eq("ello e"));

EXPECT_FALSE(CordRepBtree::IsDataEdge(concat));
EXPECT_FALSE(CordRepBtree::IsDataEdge(bad_substr));
#if defined(GTEST_HAS_DEATH_TEST) && !defined(NDEBUG)
EXPECT_DEATH(CordRepBtree::EdgeData(concat), ".*");
EXPECT_DEATH(CordRepBtree::EdgeDataPtr(concat), ".*");
EXPECT_DEATH(CordRepBtree::EdgeData(bad_substr), ".*");
EXPECT_DEATH(CordRepBtree::EdgeDataPtr(bad_substr), ".*");
#endif

CordRep::Unref(bad_substr);
CordRep::Unref(concat);
CordRep::Unref(substr2);
CordRep::Unref(substr1);
CordRep::Unref(external);
Expand Down Expand Up @@ -1006,50 +1000,6 @@ TEST_P(CordRepBtreeTest, AddLargeDataToLeaf) {
}
}

TEST_P(CordRepBtreeDualTest, CreateFromConcat) {
AutoUnref refs;
CordRep* flats[] = {MakeFlat("abcdefgh"), MakeFlat("ijklm"),
MakeFlat("nopqrstuv"), MakeFlat("wxyz")};
auto* left = MakeConcat(flats[0], flats[1]);
auto* right = MakeConcat(flats[2], refs.RefIf(first_shared(), flats[3]));
auto* concat = refs.RefIf(second_shared(), MakeConcat(left, right));
CordRepBtree* result = CordRepBtree::Create(concat);
ASSERT_TRUE(CordRepBtree::IsValid(result));
EXPECT_THAT(result->length, Eq(26));
EXPECT_THAT(CordToString(result), Eq("abcdefghijklmnopqrstuvwxyz"));
CordRep::Unref(result);
}

TEST_P(CordRepBtreeDualTest, AppendConcat) {
AutoUnref refs;
CordRep* flats[] = {MakeFlat("defgh"), MakeFlat("ijklm"),
MakeFlat("nopqrstuv"), MakeFlat("wxyz")};
auto* left = MakeConcat(flats[0], flats[1]);
auto* right = MakeConcat(flats[2], refs.RefIf(first_shared(), flats[3]));
auto* concat = refs.RefIf(second_shared(), MakeConcat(left, right));
CordRepBtree* result = CordRepBtree::Create(MakeFlat("abc"));
result = CordRepBtree::Append(result, concat);
ASSERT_TRUE(CordRepBtree::IsValid(result));
EXPECT_THAT(result->length, Eq(26));
EXPECT_THAT(CordToString(result), Eq("abcdefghijklmnopqrstuvwxyz"));
CordRep::Unref(result);
}

TEST_P(CordRepBtreeDualTest, PrependConcat) {
AutoUnref refs;
CordRep* flats[] = {MakeFlat("abcdefgh"), MakeFlat("ijklm"),
MakeFlat("nopqrstuv"), MakeFlat("wx")};
auto* left = MakeConcat(flats[0], flats[1]);
auto* right = MakeConcat(flats[2], refs.RefIf(first_shared(), flats[3]));
auto* concat = refs.RefIf(second_shared(), MakeConcat(left, right));
CordRepBtree* result = CordRepBtree::Create(MakeFlat("yz"));
result = CordRepBtree::Prepend(result, concat);
ASSERT_TRUE(CordRepBtree::IsValid(result));
EXPECT_THAT(result->length, Eq(26));
EXPECT_THAT(CordToString(result), Eq("abcdefghijklmnopqrstuvwxyz"));
CordRep::Unref(result);
}

TEST_P(CordRepBtreeTest, CreateFromTreeReturnsTree) {
AutoUnref refs;
CordRepBtree* leaf = CordRepBtree::Create(MakeFlat("Hello world"));
Expand Down
Loading

0 comments on commit 73316fc

Please sign in to comment.