[compiler-rt] [scudo] Support linking with index in IntrusiveList (PR #101262)

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 5 11:52:52 PDT 2024


================
@@ -11,17 +11,103 @@
 
 #include "internal_defs.h"
 
+// TODO: Move the helpers to a header.
+namespace {
+template <typename T> struct isPointer {
+  static constexpr bool value = false;
+};
+
+template <typename T> struct isPointer<T *> {
+  static constexpr bool value = true;
+};
+} // namespace
+
 namespace scudo {
 
 // Intrusive POD singly and doubly linked list.
 // An object with all zero fields should represent a valid empty list. clear()
 // should be called on all non-zero-initialized objects before using.
+//
+// The intrusive list requires the member `Next` (and `Prev` if doubly linked
+// list)` defined in the node type. The type of `Next`/`Prev` can be a pointer
+// or an index to an array. For example, if the storage of the nodes is an
+// array, instead of using pointer type, linking with index type can save some
+// space.
+//
+// There are two things to be noticed while using index type,
+//   1. Call init() to set up the base address of the array.
+//   2. Define `EndOfListVal` as the nil of the list.
 
-template <class T> class IteratorBase {
+template <class T, bool LinkWithPtr = isPointer<decltype(T::Next)>::value>
----------------
ChiaHungDuan wrote:

Will make this `LinkWithPtr = true` so it looks more intuitive 

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


More information about the llvm-commits mailing list