diff options
author | Michael Jones <michaelrj@google.com> | 2024-06-14 13:31:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-14 13:31:40 -0700 |
commit | cccc43725798de5371eb893f11f3940e6a954a0f (patch) | |
tree | da9c7a6ed9e3d3be5ea8bb97d29a9635ce9d9de9 /libc/src | |
parent | 38d8f6e58430357856926498185b2b221afc1d2c (diff) | |
download | llvm-cccc43725798de5371eb893f11f3940e6a954a0f.zip llvm-cccc43725798de5371eb893f11f3940e6a954a0f.tar.gz llvm-cccc43725798de5371eb893f11f3940e6a954a0f.tar.bz2 |
[libc] add LIBC_INLINE annotations to BlockStore (#95573)
Add the LIBC_INLINE annotation to all the functions in blockstore.
Diffstat (limited to 'libc/src')
-rw-r--r-- | libc/src/__support/blockstore.h | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/libc/src/__support/blockstore.h b/libc/src/__support/blockstore.h index ac0eb22..bcab750 100644 --- a/libc/src/__support/blockstore.h +++ b/libc/src/__support/blockstore.h @@ -44,7 +44,7 @@ protected: struct Pair { Block *first, *second; }; - Pair get_last_blocks() { + LIBC_INLINE Pair get_last_blocks() { if (REVERSE_ORDER) return {current, current->next}; Block *prev = nullptr; @@ -55,20 +55,20 @@ protected: return {curr, prev}; } - Block *get_last_block() { return get_last_blocks().first; } + LIBC_INLINE Block *get_last_block() { return get_last_blocks().first; } public: - constexpr BlockStore() = default; - ~BlockStore() = default; + LIBC_INLINE constexpr BlockStore() = default; + LIBC_INLINE ~BlockStore() = default; class Iterator { Block *block; size_t index; public: - constexpr Iterator(Block *b, size_t i) : block(b), index(i) {} + LIBC_INLINE constexpr Iterator(Block *b, size_t i) : block(b), index(i) {} - Iterator &operator++() { + LIBC_INLINE Iterator &operator++() { if (REVERSE_ORDER) { if (index == 0) return *this; @@ -92,23 +92,24 @@ public: return *this; } - T &operator*() { + LIBC_INLINE T &operator*() { size_t true_index = REVERSE_ORDER ? index - 1 : index; return *reinterpret_cast<T *>(block->data + sizeof(T) * true_index); } - bool operator==(const Iterator &rhs) const { + LIBC_INLINE bool operator==(const Iterator &rhs) const { return block == rhs.block && index == rhs.index; } - bool operator!=(const Iterator &rhs) const { + LIBC_INLINE bool operator!=(const Iterator &rhs) const { return block != rhs.block || index != rhs.index; } }; - static void destroy(BlockStore<T, BLOCK_SIZE, REVERSE_ORDER> *block_store); + LIBC_INLINE static void + destroy(BlockStore<T, BLOCK_SIZE, REVERSE_ORDER> *block_store); - T *new_obj() { + LIBC_INLINE T *new_obj() { if (fill_count == BLOCK_SIZE) { AllocChecker ac; auto new_block = new (ac) Block(); @@ -128,7 +129,7 @@ public: return obj; } - [[nodiscard]] bool push_back(const T &value) { + [[nodiscard]] LIBC_INLINE bool push_back(const T &value) { T *ptr = new_obj(); if (ptr == nullptr) return false; @@ -136,12 +137,12 @@ public: return true; } - T &back() { + LIBC_INLINE T &back() { return *reinterpret_cast<T *>(get_last_block()->data + sizeof(T) * (fill_count - 1)); } - void pop_back() { + LIBC_INLINE void pop_back() { fill_count--; if (fill_count || current == &first) return; @@ -159,16 +160,16 @@ public: fill_count = BLOCK_SIZE; } - bool empty() const { return current == &first && !fill_count; } + LIBC_INLINE bool empty() const { return current == &first && !fill_count; } - Iterator begin() { + LIBC_INLINE Iterator begin() { if (REVERSE_ORDER) return Iterator(current, fill_count); else return Iterator(&first, 0); } - Iterator end() { + LIBC_INLINE Iterator end() { if (REVERSE_ORDER) return Iterator(&first, 0); else @@ -177,7 +178,7 @@ public: }; template <typename T, size_t BLOCK_SIZE, bool REVERSE_ORDER> -void BlockStore<T, BLOCK_SIZE, REVERSE_ORDER>::destroy( +LIBC_INLINE void BlockStore<T, BLOCK_SIZE, REVERSE_ORDER>::destroy( BlockStore<T, BLOCK_SIZE, REVERSE_ORDER> *block_store) { if (REVERSE_ORDER) { auto current = block_store->current; |