diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2022-09-01 15:38:17 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-01 15:38:17 -0400 |
| commit | be8497804f803c02cfab1aa2c54d921042e90ec9 (patch) | |
| tree | c9451382ba2bf112848441f9d61470a90ed764ee /source/core | |
| parent | 174048f26c147e31a6f72907a3af5dfafeedb877 (diff) | |
Remove artifact from SourceFile (#2384)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Make DownstreamCompileOptions use POD types.
* CharSliceAllocator -> SliceAllocator
Added SliceConverter
CharSliceCaster -> SliceCaster
* First attempt at zero terminating around blobs.
* Fix clang warning.
* Add SlangTerminatedChars
Make Blob implementations support it.
Make most blobs 'terminated'.
* Fix bug setting up sourceFiles for CommandLineDownstreamCompiler.
* Traffic in TerminatedCharSlice for sourceFiles.
Use ArtifactDesc to generate temporary file names for source.
* Fix typo in testing for shared library/C++.
* Working with source being passed as artifacts to DownstreamCompiler.
* Use artifacts in SourceManager/SourceFile.
* Support infering extension from the original file extension.
* * Infer extension if can't determine from the artifact type
* Split IOSFile/IExtFile representations
* Move responsibility for creating OS file to the handler.
* Disable the check memory path.
* Remove artifact from SourceFile.
Lazily generate SourceFile from artifacts as needed.
* Fix some small bugs.
* Remove maybeAddArtifact.
* Load artifacts if repro capture is enabled.
* Remove adding by string, because doing so means source will be allocated twice or there is a potential race around ref counting to the contained String.
* Add built in source as a blob.
* Fix warning.
* Make StringBlob own the contents if moved.
Fix some compilation issues.
* Share StringBlob uniqueness code.
* Do move unique on Ctor.
* Change MoveUnique to not have any values.
* MoveUnique can more sensibly be a struct.
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-blob.cpp | 29 | ||||
| -rw-r--r-- | source/core/slang-blob.h | 20 |
2 files changed, 43 insertions, 6 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) diff --git a/source/core/slang-blob.h b/source/core/slang-blob.h index 1acf279ef..e528f55a8 100644 --- a/source/core/slang-blob.h +++ b/source/core/slang-blob.h @@ -50,17 +50,25 @@ public: SLANG_NO_THROW size_t SLANG_MCALL getBufferSize() SLANG_OVERRIDE { return m_string.getLength(); } static ComPtr<ISlangBlob> create(const String& in) { return ComPtr<ISlangBlob>(new StringBlob(in)); } - static ComPtr<ISlangBlob> moveCreate(String& in) - { - auto blob = new StringBlob; - blob->m_string.swapWith(in); - return ComPtr<ISlangBlob>(blob); - } + + /// Moves from in into the created blob. + /// NOTE! That will only use the representation from in, if it is *unique* + /// otherwise it will make a new copy. + /// This is so that StringBlob won't hold a reference count via a string held externally. + /// In contrast StringBlob::create *may* share the representation. + static ComPtr<ISlangBlob> moveCreate(String& in); + static ComPtr<ISlangBlob> moveCreate(String&& in); protected: + /// A type that is only used to differentiate a constructor. Can construct with + /// MoveUnique{} + struct MoveUnique {}; + explicit StringBlob(String const& string) : m_string(string) {} + + StringBlob(MoveUnique, String& string); StringBlob() {} /// Get the contained string |
