Skip to content

Commit cccc437

Browse files
[libc] add LIBC_INLINE annotations to BlockStore (llvm#95573)
Add the LIBC_INLINE annotation to all the functions in blockstore.
1 parent 38d8f6e commit cccc437

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

libc/src/__support/blockstore.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class BlockStore {
4444
struct Pair {
4545
Block *first, *second;
4646
};
47-
Pair get_last_blocks() {
47+
LIBC_INLINE Pair get_last_blocks() {
4848
if (REVERSE_ORDER)
4949
return {current, current->next};
5050
Block *prev = nullptr;
@@ -55,20 +55,20 @@ class BlockStore {
5555
return {curr, prev};
5656
}
5757

58-
Block *get_last_block() { return get_last_blocks().first; }
58+
LIBC_INLINE Block *get_last_block() { return get_last_blocks().first; }
5959

6060
public:
61-
constexpr BlockStore() = default;
62-
~BlockStore() = default;
61+
LIBC_INLINE constexpr BlockStore() = default;
62+
LIBC_INLINE ~BlockStore() = default;
6363

6464
class Iterator {
6565
Block *block;
6666
size_t index;
6767

6868
public:
69-
constexpr Iterator(Block *b, size_t i) : block(b), index(i) {}
69+
LIBC_INLINE constexpr Iterator(Block *b, size_t i) : block(b), index(i) {}
7070

71-
Iterator &operator++() {
71+
LIBC_INLINE Iterator &operator++() {
7272
if (REVERSE_ORDER) {
7373
if (index == 0)
7474
return *this;
@@ -92,23 +92,24 @@ class BlockStore {
9292
return *this;
9393
}
9494

95-
T &operator*() {
95+
LIBC_INLINE T &operator*() {
9696
size_t true_index = REVERSE_ORDER ? index - 1 : index;
9797
return *reinterpret_cast<T *>(block->data + sizeof(T) * true_index);
9898
}
9999

100-
bool operator==(const Iterator &rhs) const {
100+
LIBC_INLINE bool operator==(const Iterator &rhs) const {
101101
return block == rhs.block && index == rhs.index;
102102
}
103103

104-
bool operator!=(const Iterator &rhs) const {
104+
LIBC_INLINE bool operator!=(const Iterator &rhs) const {
105105
return block != rhs.block || index != rhs.index;
106106
}
107107
};
108108

109-
static void destroy(BlockStore<T, BLOCK_SIZE, REVERSE_ORDER> *block_store);
109+
LIBC_INLINE static void
110+
destroy(BlockStore<T, BLOCK_SIZE, REVERSE_ORDER> *block_store);
110111

111-
T *new_obj() {
112+
LIBC_INLINE T *new_obj() {
112113
if (fill_count == BLOCK_SIZE) {
113114
AllocChecker ac;
114115
auto new_block = new (ac) Block();
@@ -128,20 +129,20 @@ class BlockStore {
128129
return obj;
129130
}
130131

131-
[[nodiscard]] bool push_back(const T &value) {
132+
[[nodiscard]] LIBC_INLINE bool push_back(const T &value) {
132133
T *ptr = new_obj();
133134
if (ptr == nullptr)
134135
return false;
135136
*ptr = value;
136137
return true;
137138
}
138139

139-
T &back() {
140+
LIBC_INLINE T &back() {
140141
return *reinterpret_cast<T *>(get_last_block()->data +
141142
sizeof(T) * (fill_count - 1));
142143
}
143144

144-
void pop_back() {
145+
LIBC_INLINE void pop_back() {
145146
fill_count--;
146147
if (fill_count || current == &first)
147148
return;
@@ -159,16 +160,16 @@ class BlockStore {
159160
fill_count = BLOCK_SIZE;
160161
}
161162

162-
bool empty() const { return current == &first && !fill_count; }
163+
LIBC_INLINE bool empty() const { return current == &first && !fill_count; }
163164

164-
Iterator begin() {
165+
LIBC_INLINE Iterator begin() {
165166
if (REVERSE_ORDER)
166167
return Iterator(current, fill_count);
167168
else
168169
return Iterator(&first, 0);
169170
}
170171

171-
Iterator end() {
172+
LIBC_INLINE Iterator end() {
172173
if (REVERSE_ORDER)
173174
return Iterator(&first, 0);
174175
else
@@ -177,7 +178,7 @@ class BlockStore {
177178
};
178179

179180
template <typename T, size_t BLOCK_SIZE, bool REVERSE_ORDER>
180-
void BlockStore<T, BLOCK_SIZE, REVERSE_ORDER>::destroy(
181+
LIBC_INLINE void BlockStore<T, BLOCK_SIZE, REVERSE_ORDER>::destroy(
181182
BlockStore<T, BLOCK_SIZE, REVERSE_ORDER> *block_store) {
182183
if (REVERSE_ORDER) {
183184
auto current = block_store->current;

0 commit comments

Comments
 (0)