diff options
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/core.natvis | 8 | ||||
| -rw-r--r-- | source/core/slang-string.cpp | 16 | ||||
| -rw-r--r-- | source/core/slang-string.h | 8 |
3 files changed, 32 insertions, 0 deletions
diff --git a/source/core/core.natvis b/source/core/core.natvis index f2547b3fe..b9e7009e4 100644 --- a/source/core/core.natvis +++ b/source/core/core.natvis @@ -102,6 +102,14 @@ </Expand> </Type> +<Type Name="Slang::RelativePtr<*,*>"> + <SmartPointer Usage="Minimal">_offset == 0 ? nullptr : ($T1*)((char*)this + _offset)</SmartPointer> + <DisplayString Condition="_offset == 0">{($T1*)0}</DisplayString> + <DisplayString Condition="_offset != 0">{($T1*)((char*)this + _offset)}</DisplayString> + <Expand> + <ExpandedItem>_offset == 0 ? nullptr : ($T1*)((char*)this + _offset)</ExpandedItem> + </Expand> +</Type> <Type Name="Slang::Safe32Ptr<*>"> <Expand> diff --git a/source/core/slang-string.cpp b/source/core/slang-string.cpp index e9804eaa8..a0612ccda 100644 --- a/source/core/slang-string.cpp +++ b/source/core/slang-string.cpp @@ -727,6 +727,22 @@ UnownedStringSlice UnownedStringSlice::subString(Index idx, Index len) const return UnownedStringSlice(m_begin + idx, m_begin + idx + len); } +int compare(UnownedStringSlice const& lhs, UnownedStringSlice const& rhs) +{ + auto lhsSize = lhs.getLength(); + auto rhsSize = rhs.getLength(); + + auto lhsData = lhs.begin(); + auto rhsData = rhs.begin(); + + auto sharedPrefixSize = std::min(lhsSize, rhsSize); + int sharedPrefixCmp = memcmp(lhsData, rhsData, sharedPrefixSize); + if (sharedPrefixCmp != 0) + return sharedPrefixCmp; + + return int(lhsSize - rhsSize); +} + bool UnownedStringSlice::operator==(ThisType const& other) const { // Note that memcmp is undefined when passed in null ptrs, so if we want to handle diff --git a/source/core/slang-string.h b/source/core/slang-string.h index 3da0db6b9..6d84a0c95 100644 --- a/source/core/slang-string.h +++ b/source/core/slang-string.h @@ -218,6 +218,14 @@ protected: char const* m_end; }; +/// Three-way comparison of string slices. +/// +/// * Returns 0 if `lhs == rhs` +/// * Returns a value < 0 if `lhs < rhs` +/// * Returns a value > 0 if `lhs > rhs` +/// +int compare(UnownedStringSlice const& lhs, UnownedStringSlice const& rhs); + // A more convenient way to make slices from *string literals* template<size_t SIZE> SLANG_FORCE_INLINE UnownedStringSlice toSlice(const char (&in)[SIZE]) |
