[libc-commits] [libc] [libc] add LIBC_INLINE annotations to BlockStore (PR #95573)

via libc-commits libc-commits at lists.llvm.org
Fri Jun 14 10:19:53 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

<details>
<summary>Changes</summary>

Add the LIBC_INLINE annotation to all the functions in blockstore.

---
Full diff: https://github.com/llvm/llvm-project/pull/95573.diff


1 Files Affected:

- (modified) libc/src/__support/blockstore.h (+19-18) 


``````````diff
diff --git a/libc/src/__support/blockstore.h b/libc/src/__support/blockstore.h
index ac0eb22692b40..bcab7504dbd6e 100644
--- a/libc/src/__support/blockstore.h
+++ b/libc/src/__support/blockstore.h
@@ -44,7 +44,7 @@ class BlockStore {
   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 @@ class BlockStore {
     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 @@ class BlockStore {
       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 @@ class BlockStore {
     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 @@ class BlockStore {
     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 @@ class BlockStore {
     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 @@ class BlockStore {
 };
 
 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;

``````````

</details>


https://github.com/llvm/llvm-project/pull/95573


More information about the libc-commits mailing list