From bd307152a8782992ebadc670ee08359922e3b5c6 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Thu, 21 Mar 2024 15:00:26 -0700 Subject: [PATCH] Simplify description of the SList data structure - Remove the fields from the templated type, so the field offsets used within the type are always constant and defined by a non-templated structure (See usage of SListBase) - Remove unused feature of SList, where the field present in the walkable structure can be configured to not be called m_Link --- src/coreclr/inc/slist.h | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/coreclr/inc/slist.h b/src/coreclr/inc/slist.h index 805413fd3da34..59576ed337919 100644 --- a/src/coreclr/inc/slist.h +++ b/src/coreclr/inc/slist.h @@ -85,14 +85,20 @@ struct SLink } }; +class SListBase +{ +public: + // used as sentinel + SLink m_link; // slink.m_pNext == Null + PTR_SLink m_pHead; + PTR_SLink m_pTail; +}; + //------------------------------------------------------------------ // class SList. Intrusive singly linked list. // // To use SList with the default instantiation, your class should -// define a data member of type SLink and named 'm_Link'. To use a -// different field name, you need to provide an explicit LinkPtr -// template argument. For example: -// 'SList' +// define a data member of type SLink and named 'm_Link'. // // SList has two different behaviours depending on boolean // fHead variable, @@ -104,8 +110,8 @@ struct SLink // argument 'fHead' // so there is no actual code size increase //-------------------------------------------------------------- -template -class SList +template +class SList : protected SListBase { public: // typedef used by the Queue class below @@ -113,16 +119,11 @@ class SList protected: - // used as sentinel - SLink m_link; // slink.m_pNext == Null - PTR_SLink m_pHead; - PTR_SLink m_pTail; - // get the list node within the object static SLink* GetLink (T* pLink) { LIMITED_METHOD_DAC_CONTRACT; - return &(pLink->*LinkPtr); + return &(pLink->m_Link); } // move to the beginning of the object given the pointer within the object @@ -138,10 +139,10 @@ class SList #if 1 // Newer compilers define offsetof to be __builtin_offsetof, which doesn't use the // old-school memory model trick to determine offset. - const UINT_PTR offset = (((UINT_PTR)&(((T *)0x1000)->*LinkPtr))-0x1000); + const UINT_PTR offset = (((UINT_PTR)&(((T *)0x1000)->m_Link))-0x1000); return (T*)__PTR(dac_cast(pLink) - offset); #else - return (T*)__PTR(dac_cast(pLink) - offsetof(T, *LinkPtr)); + return (T*)__PTR(dac_cast(pLink) - offsetof(T, m_Link)); #endif } }