Skip to content

Commit cbab5b2

Browse files
committed
Rename freelist2->freelist
1 parent 18e5b4c commit cbab5b2

File tree

6 files changed

+49
-49
lines changed

6 files changed

+49
-49
lines changed

libc/src/__support/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ add_header_library(
1717
add_header_library(
1818
freelist
1919
HDRS
20-
freelist2.h
20+
freelist.h
2121
DEPENDS
2222
libc.src.__support.fixedvector
2323
libc.src.__support.CPP.array

libc/src/__support/freelist2.h renamed to libc/src/__support/freelist.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC___SUPPORT_FREELIST2_H
10-
#define LLVM_LIBC_SRC___SUPPORT_FREELIST2_H
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_FREELIST_H
10+
#define LLVM_LIBC_SRC___SUPPORT_FREELIST_H
1111

1212
#include "block.h"
1313

1414
namespace LIBC_NAMESPACE_DECL {
1515

1616
/// A circularly-linked FIFO list node storing a free Block. A list is a
17-
/// FreeList2*; nullptr is an empty list. All Blocks on a list are the same
17+
/// FreeList*; nullptr is an empty list. All Blocks on a list are the same
1818
/// size.
1919
///
2020
/// Accessing free blocks in FIFO order maximizes the amount of time before a
2121
/// free block is reused. This in turn maximizes the number of opportunities for
2222
/// it to be coalesced with an adjacent block, which tends to reduce heap
2323
/// fragmentation.
24-
class FreeList2 {
24+
class FreeList {
2525
public:
2626
Block<> *block() const {
2727
return const_cast<Block<> *>(Block<>::from_usable_space(this));
@@ -30,30 +30,30 @@ class FreeList2 {
3030
/// @returns Size for all blocks on the list.
3131
size_t size() const { return block()->inner_size(); }
3232

33-
/// Push to the back. The Block must be able to contain a FreeList2.
34-
static void push(FreeList2 *&list, Block<> *block);
33+
/// Push to the back. The Block must be able to contain a FreeList.
34+
static void push(FreeList *&list, Block<> *block);
3535

3636
/// Pop the front.
37-
static void pop(FreeList2 *&list);
37+
static void pop(FreeList *&list);
3838

3939
protected:
4040
/// Push an already-constructed node to the back.
41-
static void push(FreeList2 *&list, FreeList2 *node);
41+
static void push(FreeList *&list, FreeList *node);
4242

4343
private:
4444
// Circularly linked pointers to adjacent nodes.
45-
FreeList2 *prev;
46-
FreeList2 *next;
45+
FreeList *prev;
46+
FreeList *next;
4747
};
4848

49-
LIBC_INLINE void FreeList2::push(FreeList2 *&list, Block<> *block) {
49+
LIBC_INLINE void FreeList::push(FreeList *&list, Block<> *block) {
5050
LIBC_ASSERT(!block->used() && "only free blocks can be placed on free lists");
51-
LIBC_ASSERT(block->inner_size_free() >= sizeof(FreeList2) &&
51+
LIBC_ASSERT(block->inner_size_free() >= sizeof(FreeList) &&
5252
"block too small to accomodate free list node");
53-
push(list, new (block->usable_space()) FreeList2);
53+
push(list, new (block->usable_space()) FreeList);
5454
}
5555

56-
LIBC_INLINE void FreeList2::pop(FreeList2 *&list) {
56+
LIBC_INLINE void FreeList::pop(FreeList *&list) {
5757
LIBC_ASSERT(list != nullptr && "cannot pop from empty list");
5858
if (list->next == list) {
5959
list = nullptr;
@@ -64,7 +64,7 @@ LIBC_INLINE void FreeList2::pop(FreeList2 *&list) {
6464
}
6565
}
6666

67-
LIBC_INLINE void FreeList2::push(FreeList2 *&list, FreeList2 *node) {
67+
LIBC_INLINE void FreeList::push(FreeList *&list, FreeList *node) {
6868
if (list) {
6969
LIBC_ASSERT(Block<>::from_usable_space(node)->outer_size() ==
7070
list->block()->outer_size() &&
@@ -80,4 +80,4 @@ LIBC_INLINE void FreeList2::push(FreeList2 *&list, FreeList2 *node) {
8080

8181
} // namespace LIBC_NAMESPACE_DECL
8282

83-
#endif // LLVM_LIBC_SRC___SUPPORT_FREELIST2_H
83+
#endif // LLVM_LIBC_SRC___SUPPORT_FREELIST_H

libc/src/__support/freestore.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ class FreeStore {
2626
Block<> *remove_best_fit(size_t size);
2727

2828
private:
29-
static constexpr size_t MIN_SIZE = sizeof(FreeList2);
29+
static constexpr size_t MIN_SIZE = sizeof(FreeList);
3030
static constexpr size_t MIN_LARGE_SIZE = sizeof(FreeTrie);
3131
static constexpr size_t NUM_SMALL_SIZES =
3232
(align_up(MIN_LARGE_SIZE) - align_up(MIN_SIZE)) / alignof(max_align_t);
3333

3434
static bool is_small(Block<> *block);
3535
static bool is_small(size_t size);
3636

37-
FreeList2 *&small_list(Block<> *block);
38-
FreeList2 **best_small_fit(size_t size);
37+
FreeList *&small_list(Block<> *block);
38+
FreeList **best_small_fit(size_t size);
3939

40-
cpp::array<FreeList2 *, NUM_SMALL_SIZES> small_lists = {nullptr};
40+
cpp::array<FreeList *, NUM_SMALL_SIZES> small_lists = {nullptr};
4141
FreeTrie *large_trie = nullptr;
4242
FreeTrie::SizeRange range = {0, 0};
4343
};
@@ -51,7 +51,7 @@ inline void FreeStore::insert(Block<> *block) {
5151
if (block->inner_size_free() < MIN_SIZE)
5252
return;
5353
if (is_small(block))
54-
FreeList2::push(small_list(block), block);
54+
FreeList::push(small_list(block), block);
5555
else
5656
FreeTrie::push(FreeTrie::find(large_trie, block->inner_size(), range),
5757
block);
@@ -61,13 +61,13 @@ inline void FreeStore::remove(Block<> *block) {
6161
LIBC_ASSERT(block->inner_size_free() >= MIN_SIZE &&
6262
"block too small to have been present");
6363
if (is_small(block)) {
64-
FreeList2 *block_list =
65-
reinterpret_cast<FreeList2 *>(block->usable_space());
66-
FreeList2 *&list = small_list(block);
64+
FreeList *block_list =
65+
reinterpret_cast<FreeList *>(block->usable_space());
66+
FreeList *&list = small_list(block);
6767
if (block_list == list)
68-
FreeList2::pop(list);
68+
FreeList::pop(list);
6969
else
70-
FreeList2::pop(block_list);
70+
FreeList::pop(block_list);
7171
} else {
7272
auto *trie = reinterpret_cast<FreeTrie *>(block->usable_space());
7373
if (trie == large_trie) {
@@ -80,11 +80,11 @@ inline void FreeStore::remove(Block<> *block) {
8080

8181
inline Block<> *FreeStore::remove_best_fit(size_t size) {
8282
if (is_small(size)) {
83-
FreeList2 **list = best_small_fit(size);
83+
FreeList **list = best_small_fit(size);
8484
if (!list)
8585
return nullptr;
8686
Block<> *block = (*list)->block();
87-
FreeList2::pop(*list);
87+
FreeList::pop(*list);
8888
return block;
8989
}
9090

@@ -106,14 +106,14 @@ inline bool FreeStore::is_small(size_t size) {
106106
return size - sizeof(Block<>::offset_type) < MIN_LARGE_SIZE;
107107
}
108108

109-
inline FreeList2 *&FreeStore::small_list(Block<> *block) {
109+
inline FreeList *&FreeStore::small_list(Block<> *block) {
110110
LIBC_ASSERT(is_small(block) && "only legal for small blocks");
111111
return small_lists[(block->inner_size_free() - MIN_SIZE) /
112112
alignof(max_align_t)];
113113
}
114114

115-
inline FreeList2 **FreeStore::best_small_fit(size_t size) {
116-
for (FreeList2 *&list : small_lists)
115+
inline FreeList **FreeStore::best_small_fit(size_t size) {
116+
for (FreeList *&list : small_lists)
117117
if (list && list->size() >= size)
118118
return &list;
119119
return nullptr;

libc/src/__support/freetrie.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
#ifndef LLVM_LIBC_SRC___SUPPORT_FREETRIE_H
1111
#define LLVM_LIBC_SRC___SUPPORT_FREETRIE_H
1212

13-
#include "freelist2.h"
13+
#include "freelist.h"
1414

1515
namespace LIBC_NAMESPACE_DECL {
1616

1717
/// A trie node containing a free list. The subtrie contains a contiguous
1818
/// SizeRange of freelists.There is no relationship between the size of this
1919
/// free list and the size ranges of the subtries.
20-
class FreeTrie : public FreeList2 {
20+
class FreeTrie : public FreeList {
2121
public:
2222
// Power-of-two range of sizes covered by a subtrie.
2323
struct SizeRange {
@@ -112,14 +112,14 @@ LIBC_INLINE void FreeTrie::push(InsertPos pos, Block<> *block) {
112112
node->lower = node->upper = nullptr;
113113
node->parent = pos.parent;
114114
}
115-
FreeList2 *list = *pos.trie;
116-
FreeList2::push(list, node);
115+
FreeList *list = *pos.trie;
116+
FreeList::push(list, node);
117117
*pos.trie = static_cast<FreeTrie *>(list);
118118
}
119119

120120
LIBC_INLINE void FreeTrie::pop(FreeTrie *&trie) {
121-
FreeList2 *list = trie;
122-
FreeList2::pop(list);
121+
FreeList *list = trie;
122+
FreeList::pop(list);
123123
FreeTrie *new_trie = static_cast<FreeTrie *>(list);
124124
if (new_trie) {
125125
// The freelist is non-empty, so copy the trie links to the new head.

libc/test/src/__support/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
2020
SUITE
2121
libc-support-tests
2222
SRCS
23-
freelist2_test.cpp
23+
freelist_test.cpp
2424
#freetrie_test.cpp
2525
DEPENDS
2626
libc.src.__support.CPP.array

libc/test/src/__support/freelist2_test.cpp renamed to libc/test/src/__support/freelist_test.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
#include <stddef.h>
1010

11-
#include "src/__support/freelist2.h"
11+
#include "src/__support/freelist.h"
1212
#include "test/UnitTest/Test.h"
1313

1414
namespace LIBC_NAMESPACE_DECL {
1515

16-
TEST(LlvmLibcFreeList2, PushPop) {
16+
TEST(LlvmLibcFreeList, PushPop) {
1717
cpp::byte mem1[1024];
1818
optional<Block<> *> maybeBlock = Block<>::init(mem1);
1919
ASSERT_TRUE(maybeBlock.has_value());
@@ -24,20 +24,20 @@ TEST(LlvmLibcFreeList2, PushPop) {
2424
ASSERT_TRUE(maybeBlock.has_value());
2525
Block<> *block2 = *maybeBlock;
2626

27-
FreeList2 *list = nullptr;
28-
FreeList2::push(list, block1);
29-
ASSERT_NE(list, static_cast<FreeList2*>(nullptr));
27+
FreeList *list = nullptr;
28+
FreeList::push(list, block1);
29+
ASSERT_NE(list, static_cast<FreeList *>(nullptr));
3030
EXPECT_EQ(list->block(), block1);
3131

32-
FreeList2::push(list, block2);
32+
FreeList::push(list, block2);
3333
EXPECT_EQ(list->block(), block1);
3434

35-
FreeList2::pop(list);
36-
ASSERT_NE(list, static_cast<FreeList2*>(nullptr));
35+
FreeList::pop(list);
36+
ASSERT_NE(list, static_cast<FreeList *>(nullptr));
3737
EXPECT_EQ(list->block(), block2);
3838

39-
FreeList2::pop(list);
40-
ASSERT_EQ(list, static_cast<FreeList2*>(nullptr));
39+
FreeList::pop(list);
40+
ASSERT_EQ(list, static_cast<FreeList *>(nullptr));
4141
}
4242

4343
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)