Skip to content

Commit ebfb76e

Browse files
Revert "[libc] Add erase function to blockstore" (#98669)
Reverts #97641 Fails under sanitizers
1 parent 9e452c1 commit ebfb76e

File tree

2 files changed

+2
-151
lines changed

2 files changed

+2
-151
lines changed

libc/src/__support/blockstore.h

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
#ifndef LLVM_LIBC_SRC___SUPPORT_BLOCKSTORE_H
1010
#define LLVM_LIBC_SRC___SUPPORT_BLOCKSTORE_H
1111

12-
#include "src/__support/CPP/array.h"
13-
#include "src/__support/CPP/new.h"
14-
#include "src/__support/CPP/type_traits.h"
15-
#include "src/__support/libc_assert.h"
1612
#include "src/__support/macros/config.h"
13+
#include <src/__support/CPP/new.h>
14+
#include <src/__support/libc_assert.h>
1715

1816
#include <stddef.h>
1917
#include <stdint.h>
@@ -100,16 +98,6 @@ class BlockStore {
10098
return *reinterpret_cast<T *>(block->data + sizeof(T) * true_index);
10199
}
102100

103-
LIBC_INLINE Iterator operator+(int i) {
104-
LIBC_ASSERT(i >= 0 &&
105-
"BlockStore iterators only support incrementation.");
106-
auto other = *this;
107-
for (int j = 0; j < i; ++j)
108-
++other;
109-
110-
return other;
111-
}
112-
113101
LIBC_INLINE bool operator==(const Iterator &rhs) const {
114102
return block == rhs.block && index == rhs.index;
115103
}
@@ -188,45 +176,6 @@ class BlockStore {
188176
else
189177
return Iterator(current, fill_count);
190178
}
191-
192-
// Removes the element at pos, then moves all the objects after back by one to
193-
// fill the hole. It's assumed that pos is a valid iterator to somewhere in
194-
// this block_store.
195-
LIBC_INLINE void erase(Iterator pos) {
196-
const Iterator last_item = Iterator(current, fill_count);
197-
if (pos == last_item) {
198-
pop_back();
199-
return;
200-
}
201-
202-
if constexpr (REVERSE_ORDER) {
203-
// REVERSE: Iterate from begin to pos
204-
const Iterator range_end = pos;
205-
Iterator cur = begin();
206-
T prev_val = *cur;
207-
++cur;
208-
T cur_val = *cur;
209-
210-
for (; cur != range_end; ++cur) {
211-
cur_val = *cur;
212-
*cur = prev_val;
213-
prev_val = cur_val;
214-
}
215-
// We will always need to move at least one item (since we know that pos
216-
// isn't the last item due to the check above).
217-
*cur = prev_val;
218-
} else {
219-
// FORWARD: Iterate from pos to end
220-
const Iterator range_end = end();
221-
Iterator cur = pos;
222-
Iterator prev = cur;
223-
++cur;
224-
225-
for (; cur != range_end; prev = cur, ++cur)
226-
*prev = *cur;
227-
}
228-
pop_back();
229-
}
230179
};
231180

232181
template <typename T, size_t BLOCK_SIZE, bool REVERSE_ORDER>

libc/test/src/__support/blockstore_test.cpp

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -64,99 +64,6 @@ class LlvmLibcBlockStoreTest : public LIBC_NAMESPACE::testing::Test {
6464
}
6565
block_store.destroy(&block_store);
6666
}
67-
68-
template <bool REVERSE> void erase_test() {
69-
using LIBC_NAMESPACE::BlockStore;
70-
BlockStore<int, 2, REVERSE> block_store;
71-
int i;
72-
73-
constexpr int ARR_SIZE = 6;
74-
75-
ASSERT_TRUE(block_store.empty());
76-
for (int i = 0; i < ARR_SIZE; i++) {
77-
ASSERT_TRUE(block_store.push_back(i + 1));
78-
}
79-
80-
// block_store state should be {1,2,3,4,5,6}
81-
82-
block_store.erase(block_store.begin());
83-
84-
// FORWARD: block_store state should be {2,3,4,5,6}
85-
// REVERSE: block_store state should be {1,2,3,4,5}
86-
87-
auto iter = block_store.begin();
88-
for (i = 0; iter != block_store.end(); ++i, ++iter) {
89-
if (!REVERSE) {
90-
ASSERT_EQ(*iter, i + 2);
91-
} else {
92-
ASSERT_EQ(*iter, (ARR_SIZE - 1) - i);
93-
}
94-
}
95-
96-
// Assert that there were the correct number of elements
97-
ASSERT_EQ(i, ARR_SIZE - 1);
98-
99-
block_store.erase(block_store.end());
100-
101-
// BOTH: block_store state should be {2,3,4,5}
102-
103-
iter = block_store.begin();
104-
for (i = 0; iter != block_store.end(); ++i, ++iter) {
105-
if (!REVERSE) {
106-
ASSERT_EQ(*iter, i + 2);
107-
} else {
108-
ASSERT_EQ(*iter, (ARR_SIZE - 1) - i);
109-
}
110-
}
111-
112-
ASSERT_EQ(i, ARR_SIZE - 2);
113-
114-
block_store.erase(block_store.begin() + 1);
115-
116-
// FORWARD: block_store state should be {2,4,5}
117-
// REVERSE: block_store state should be {2,3,5}
118-
119-
const int FORWARD_RESULTS[] = {2, 4, 5};
120-
const int REVERSE_RESULTS[] = {2, 3, 5};
121-
122-
iter = block_store.begin();
123-
for (i = 0; iter != block_store.end(); ++i, ++iter) {
124-
if (!REVERSE) {
125-
ASSERT_EQ(*iter, FORWARD_RESULTS[i]);
126-
} else {
127-
ASSERT_EQ(*iter, REVERSE_RESULTS[ARR_SIZE - 4 - i]); // reversed
128-
}
129-
}
130-
131-
ASSERT_EQ(i, ARR_SIZE - 3);
132-
133-
block_store.erase(block_store.begin() + 1);
134-
// BOTH: block_store state should be {2,5}
135-
136-
iter = block_store.begin();
137-
if (!REVERSE) {
138-
ASSERT_EQ(*iter, 2);
139-
ASSERT_EQ(*(iter + 1), 5);
140-
} else {
141-
ASSERT_EQ(*iter, 5);
142-
ASSERT_EQ(*(iter + 1), 2);
143-
}
144-
145-
block_store.erase(block_store.begin());
146-
// FORWARD: block_store state should be {5}
147-
// REVERSE: block_store state should be {2}
148-
iter = block_store.begin();
149-
if (!REVERSE) {
150-
ASSERT_EQ(*iter, 5);
151-
} else {
152-
ASSERT_EQ(*iter, 2);
153-
}
154-
155-
block_store.erase(block_store.begin());
156-
// BOTH: block_store state should be {}
157-
158-
block_store.destroy(&block_store);
159-
}
16067
};
16168

16269
TEST_F(LlvmLibcBlockStoreTest, PopulateAndIterate4) {
@@ -193,8 +100,3 @@ TEST_F(LlvmLibcBlockStoreTest, Empty) {
193100
empty_test<false>();
194101
empty_test<true>();
195102
}
196-
197-
TEST_F(LlvmLibcBlockStoreTest, Erase) {
198-
erase_test<false>();
199-
erase_test<true>();
200-
}

0 commit comments

Comments
 (0)