summaryrefslogtreecommitdiffstats
path: root/source/core/slang-string-slice-pool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/slang-string-slice-pool.cpp')
-rw-r--r--source/core/slang-string-slice-pool.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/source/core/slang-string-slice-pool.cpp b/source/core/slang-string-slice-pool.cpp
index be7bec785..24187ba5c 100644
--- a/source/core/slang-string-slice-pool.cpp
+++ b/source/core/slang-string-slice-pool.cpp
@@ -59,6 +59,23 @@ StringSlicePool::Handle StringSlicePool::add(const Slice& slice)
return Handle(index);
}
+bool StringSlicePool::findOrAdd(const Slice& slice, Handle& outHandle)
+{
+ Handle newHandle = Handle(m_slices.getCount());
+ const Handle* handlePtr = m_map.TryGetValueOrAdd(slice, newHandle);
+ if (handlePtr)
+ {
+ outHandle = *handlePtr;
+ return true;
+ }
+
+ // Need to add
+ UnownedStringSlice scopeSlice(m_arena.allocateString(slice.begin(), slice.getLength()), slice.getLength());
+ m_slices.add(scopeSlice);
+ outHandle = newHandle;
+ return false;
+}
+
StringSlicePool::Handle StringSlicePool::add(StringRepresentation* stringRep)
{
if (stringRep == nullptr && m_style == Style::Default)