summaryrefslogtreecommitdiffstats
path: root/source/core/slang-blob.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/core/slang-blob.cpp')
-rw-r--r--source/core/slang-blob.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/source/core/slang-blob.cpp b/source/core/slang-blob.cpp
index 6cf5214cc..a4acb98cb 100644
--- a/source/core/slang-blob.cpp
+++ b/source/core/slang-blob.cpp
@@ -35,6 +35,25 @@ void* BlobBase::castAs(const SlangUUID& guid)
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! StringBlob !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
+StringBlob::StringBlob(MoveUnique, String& in)
+{
+ auto rep = in.getStringRepresentation();
+ if (rep && !rep->isUniquelyReferenced())
+ {
+ // Make a new unique copy
+ m_string = in.getUnownedSlice();
+
+ // Move out of in
+ String tmp;
+ tmp.swapWith(in);
+ }
+ else
+ {
+ // Must either not have a rep or be unique
+ m_string.swapWith(in);
+ }
+}
+
void* StringBlob::castAs(const SlangUUID& guid)
{
if (auto intf = getInterface(guid))
@@ -59,6 +78,16 @@ void* StringBlob::getObject(const Guid& guid)
return nullptr;
}
+/* static */ComPtr<ISlangBlob> StringBlob::moveCreate(String& in)
+{
+ return ComPtr<ISlangBlob>(new StringBlob(MoveUnique{}, in));
+}
+
+/* static */ComPtr<ISlangBlob> StringBlob::moveCreate(String&& in)
+{
+ return ComPtr<ISlangBlob>(new StringBlob(MoveUnique{}, in));
+}
+
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RawBlob !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
void* RawBlob::castAs(const SlangUUID& guid)