Tidy up std::{set,vector} + arena

This commit is contained in:
2024-01-22 13:22:52 -08:00
parent bcc9195cdb
commit 5456475db6

View File

@@ -162,6 +162,15 @@ template <class T> struct ArenaAlloc {
private:
};
template <class T> using Vector = std::vector<T, ArenaAlloc<T>>;
template <class T> auto vector(Arena &arena) {
return Vector<T>(ArenaAlloc<T>(&arena));
}
template <class T> using Set = std::set<T, std::less<T>, ArenaAlloc<T>>;
template <class T> auto set(Arena &arena) {
return Set<T>(ArenaAlloc<T>(&arena));
}
template <class T, class U>
bool operator==(const ArenaAlloc<T> &lhs, const ArenaAlloc<U> &rhs) {
return lhs.arena == rhs.arena;
@@ -843,8 +852,7 @@ bool checkCorrectness(Node *node, ReferenceImpl &refImpl) {
bool success = true;
// Check bst invariant
Arena arena;
std::vector<std::string_view, ArenaAlloc<std::string_view>> keys{
ArenaAlloc<std::string_view>(&arena)};
auto keys = vector<std::string_view>(arena);
for (auto iter = extrema(node, false); iter != nullptr;
iter = next(iter, true)) {
keys.push_back(std::string_view((char *)(iter + 1), iter->len));
@@ -998,8 +1006,7 @@ struct __attribute__((__visibility__("hidden"))) ConflictSet::Impl {
runInterleaved(stepwiseInserts);
std::vector<Node *, ArenaAlloc<Node *>> workList{
ArenaAlloc<Node *>(&arena)};
auto workList = vector<Node *>(arena);
workList.reserve(count);
for (int i = 0; i < count; ++i) {
Node *node = *stepwiseInserts[i].current;
@@ -1048,7 +1055,7 @@ struct __attribute__((__visibility__("hidden"))) ConflictSet::Impl {
~Impl() {
Arena arena;
std::vector<Node *, ArenaAlloc<Node *>> toFree{ArenaAlloc<Node *>(&arena)};
auto toFree = vector<Node *>(arena);
if (root != nullptr) {
toFree.push_back(root);
}
@@ -1240,9 +1247,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
int numWrites = gArbitrary.bounded(10);
int64_t v = ++writeVersion;
auto *writes = new (arena) ConflictSet::WriteRange[numWrites];
std::set<std::string_view, std::less<std::string_view>,
ArenaAlloc<std::string_view>>
keys{ArenaAlloc<int>(&arena)};
auto keys = set<std::string_view>(arena);
while (int(keys.size()) < numWrites) {
if (!gArbitrary.hasEntropy()) {
// Tell the fuzzer it's not interesting
@@ -1271,9 +1276,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
int numReads = gArbitrary.bounded(10);
int64_t v = writeVersion - gArbitrary.bounded(10);
auto *reads = new (arena) ConflictSet::ReadRange[numReads];
std::set<std::string_view, std::less<std::string_view>,
ArenaAlloc<std::string_view>>
keys{ArenaAlloc<int>(&arena)};
auto keys = set<std::string_view>(arena);
while (int(keys.size()) < numReads) {
if (!gArbitrary.hasEntropy()) {
// Tell the fuzzer it's not interesting