summaryrefslogtreecommitdiffstats
path: root/source/core/slang-string.h
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-02-23 10:31:05 -0800
committerGitHub <noreply@github.com>2025-02-23 10:31:05 -0800
commit51ad07d1fbffd41c758eba172aa77ebba3204924 (patch)
treefadd788714c4ad37830846b0274d56b5ae1eff56 /source/core/slang-string.h
parent0101e5ab59a1678ed7212913c3880edfaf039537 (diff)
Improve performance when compiling small shaders. (#6396)
Improve performance when compiling small shaders. Avoid copying witness table entries that are not getting used during linking. Avoid copying auto-diff related decorations and derivative functions during linking, if the user modules doesn't use autodiff. Cache operator overload resolution results on global session, so each new Session doesn't need to repetitively run through overload resolution from scratch.
Diffstat (limited to 'source/core/slang-string.h')
-rw-r--r--source/core/slang-string.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/source/core/slang-string.h b/source/core/slang-string.h
index 24b119383..3da0db6b9 100644
--- a/source/core/slang-string.h
+++ b/source/core/slang-string.h
@@ -790,6 +790,57 @@ public:
UnownedStringSlice getUnownedSlice() const { return StringRepresentation::asSlice(m_buffer); }
};
+class ImmutableHashedString
+{
+public:
+ String slice;
+ HashCode64 hashCode;
+ ImmutableHashedString()
+ : hashCode(0)
+ {
+ }
+ ImmutableHashedString(const UnownedStringSlice& slice)
+ : slice(slice), hashCode(slice.getHashCode())
+ {
+ }
+ ImmutableHashedString(const char* begin, const char* end)
+ : slice(begin, end), hashCode(slice.getHashCode())
+ {
+ }
+ ImmutableHashedString(const char* begin, size_t len)
+ : slice(UnownedStringSlice(begin, len)), hashCode(slice.getHashCode())
+ {
+ }
+ ImmutableHashedString(const char* begin)
+ : slice(begin), hashCode(slice.getHashCode())
+ {
+ }
+ ImmutableHashedString(const String& str)
+ : slice(str), hashCode(str.getHashCode())
+ {
+ }
+ ImmutableHashedString(String&& str)
+ : slice(_Move(str)), hashCode(str.getHashCode())
+ {
+ }
+ ImmutableHashedString(const ImmutableHashedString& other) = default;
+ ImmutableHashedString& operator=(const ImmutableHashedString& other) = default;
+ bool operator==(const ImmutableHashedString& other) const
+ {
+ return hashCode == other.hashCode && slice == other.slice;
+ }
+ bool operator!=(const ImmutableHashedString& other) const
+ {
+ return hashCode != other.hashCode || slice != other.slice;
+ }
+ bool operator==(const UnownedStringSlice& other) const { return slice == other; }
+ bool operator!=(const UnownedStringSlice& other) const { return slice != other; }
+ bool operator==(const String& other) const { return slice == other.getUnownedSlice(); }
+ bool operator!=(const String& other) const { return slice != other.getUnownedSlice(); }
+ bool operator==(const char* other) const { return slice == UnownedStringSlice(other); }
+ HashCode64 getHashCode() const { return hashCode; }
+};
+
class SLANG_RT_API StringBuilder : public String
{
private: