Skip to content

Commit 93b8364

Browse files
committed
Revert "[libc] Use best-fit binary trie to make malloc logarithmic (#117065)"
This reverts commit b05600d. riscv32 unit test still broken
1 parent 31ce47b commit 93b8364

18 files changed

+472
-1186
lines changed

libc/fuzzing/__support/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,3 @@ add_libc_fuzzer(
2323
COMPILE_OPTIONS
2424
-D__LIBC_EXPLICIT_SIMD_OPT
2525
)
26-
27-
add_libc_fuzzer(
28-
freelist_heap_fuzz
29-
SRCS
30-
freelist_heap_fuzz.cpp
31-
DEPENDS
32-
libc.src.__support.freelist_heap
33-
)

libc/fuzzing/__support/freelist_heap_fuzz.cpp

Lines changed: 0 additions & 227 deletions
This file was deleted.

libc/src/__support/CMakeLists.txt

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,25 @@ add_header_library(
1414
libc.src.__support.CPP.type_traits
1515
)
1616

17-
add_object_library(
17+
add_header_library(
1818
freelist
1919
HDRS
2020
freelist.h
21-
SRCS
22-
freelist.cpp
2321
DEPENDS
24-
.block
2522
libc.src.__support.fixedvector
2623
libc.src.__support.CPP.array
2724
libc.src.__support.CPP.cstddef
2825
libc.src.__support.CPP.new
2926
libc.src.__support.CPP.span
3027
)
3128

32-
add_object_library(
33-
freetrie
34-
HDRS
35-
freetrie.h
36-
SRCS
37-
freetrie.cpp
38-
DEPENDS
39-
.block
40-
.freelist
41-
)
42-
43-
add_header_library(
44-
freestore
45-
HDRS
46-
freestore.h
47-
DEPENDS
48-
.freetrie
49-
)
50-
5129
add_header_library(
5230
freelist_heap
5331
HDRS
5432
freelist_heap.h
5533
DEPENDS
5634
.block
57-
.freestore
35+
.freelist
5836
libc.src.__support.CPP.cstddef
5937
libc.src.__support.CPP.array
6038
libc.src.__support.CPP.optional

libc/src/__support/block.h

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,32 +174,16 @@ class Block {
174174
return inner_size - sizeof(prev_) + BLOCK_OVERHEAD;
175175
}
176176

177-
/// @returns The number of usable bytes inside the block were it to be
178-
/// allocated.
177+
/// @returns The number of usable bytes inside the block.
179178
size_t inner_size() const {
180179
if (!next())
181180
return 0;
182181
return inner_size(outer_size());
183182
}
184183

185-
/// @returns The number of usable bytes inside a block with the given outer
186-
/// size were it to be allocated.
187184
static size_t inner_size(size_t outer_size) {
188185
// The usable region includes the prev_ field of the next block.
189-
return inner_size_free(outer_size) + sizeof(prev_);
190-
}
191-
192-
/// @returns The number of usable bytes inside the block if it remains free.
193-
size_t inner_size_free() const {
194-
if (!next())
195-
return 0;
196-
return inner_size_free(outer_size());
197-
}
198-
199-
/// @returns The number of usable bytes inside a block with the given outer
200-
/// size if it remains free.
201-
static size_t inner_size_free(size_t outer_size) {
202-
return outer_size - BLOCK_OVERHEAD;
186+
return outer_size - BLOCK_OVERHEAD + sizeof(prev_);
203187
}
204188

205189
/// @returns A pointer to the usable space inside this block.
@@ -217,11 +201,14 @@ class Block {
217201

218202
/// Attempts to split this block.
219203
///
220-
/// If successful, the block will have an inner size of at least
221-
/// `new_inner_size`, rounded to ensure that the split point is on an
222-
/// ALIGNMENT boundary. The remaining space will be returned as a new block.
223-
/// Note that the prev_ field of the next block counts as part of the inner
224-
/// size of the returnd block.
204+
/// If successful, the block will have an inner size of `new_inner_size`,
205+
/// rounded to ensure that the split point is on an ALIGNMENT boundary. The
206+
/// remaining space will be returned as a new block. Note that the prev_ field
207+
/// of the next block counts as part of the inner size of the returnd block.
208+
///
209+
/// This method may fail if the remaining space is too small to hold a new
210+
/// block. If this method fails for any reason, the original block is
211+
/// unmodified.
225212
optional<Block *> split(size_t new_inner_size);
226213

227214
/// Merges this block with the one that comes after it.
@@ -455,7 +442,7 @@ Block<OffsetType, kAlign>::split(size_t new_inner_size) {
455442
// The prev_ field of the next block is always available, so there is a
456443
// minimum size to a block created through splitting.
457444
if (new_inner_size < sizeof(prev_))
458-
new_inner_size = sizeof(prev_);
445+
return {};
459446

460447
size_t old_inner_size = inner_size();
461448
new_inner_size =

libc/src/__support/freelist.cpp

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)