summaryrefslogtreecommitdiffstats
path: root/source/compiler-core/slang-slice-allocator.h
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/compiler-core/slang-slice-allocator.h
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/compiler-core/slang-slice-allocator.h')
-rw-r--r--source/compiler-core/slang-slice-allocator.h72
1 files changed, 44 insertions, 28 deletions
diff --git a/source/compiler-core/slang-slice-allocator.h b/source/compiler-core/slang-slice-allocator.h
index 8d61fa211..504fbe1b7 100644
--- a/source/compiler-core/slang-slice-allocator.h
+++ b/source/compiler-core/slang-slice-allocator.h
@@ -2,12 +2,11 @@
#ifndef SLANG_SLICE_ALLOCATOR_H
#define SLANG_SLICE_ALLOCATOR_H
-// Has definition of CharSlice
+// Has definition of CharSlice
+#include "../core/slang-memory-arena.h"
#include "slang-artifact.h"
#include "slang-com-ptr.h"
-#include "../core/slang-memory-arena.h"
-
namespace Slang
{
@@ -16,50 +15,64 @@ struct SliceAllocator;
struct SliceUtil
{
- /// Convert into a list of strings
+ /// Convert into a list of strings
static List<String> toList(const Slice<TerminatedCharSlice>& in);
- /// Gets a 0 terminated string from a blob. If not possible returns nullptr
+ /// Gets a 0 terminated string from a blob. If not possible returns nullptr
static const char* getTerminated(ISlangBlob* blob, TerminatedCharSlice& outSlice);
- /// NOTE! the slice is only guarenteed to stay in scope whilst the blob does
+ /// NOTE! the slice is only guarenteed to stay in scope whilst the blob does
static TerminatedCharSlice toTerminatedCharSlice(SliceAllocator& allocator, ISlangBlob* blob);
- ///
+ ///
static TerminatedCharSlice toTerminatedCharSlice(StringBuilder& storage, ISlangBlob* blob);
- /// The slice will only be in scope whilst the string is
- static TerminatedCharSlice asTerminatedCharSlice(const String& in) { auto unowned = in.getUnownedSlice(); return TerminatedCharSlice(unowned.begin(), unowned.getLength()); }
+ /// The slice will only be in scope whilst the string is
+ static TerminatedCharSlice asTerminatedCharSlice(const String& in)
+ {
+ auto unowned = in.getUnownedSlice();
+ return TerminatedCharSlice(unowned.begin(), unowned.getLength());
+ }
- /// Get string as a char slice
- static CharSlice asCharSlice(const String& in) { auto unowned = in.getUnownedSlice(); return CharSlice(unowned.begin(), unowned.getLength()); }
+ /// Get string as a char slice
+ static CharSlice asCharSlice(const String& in)
+ {
+ auto unowned = in.getUnownedSlice();
+ return CharSlice(unowned.begin(), unowned.getLength());
+ }
- template <typename T>
- static Slice<T*> asSlice(const List<ComPtr<T>>& list) { return makeSlice((T* const*)list.getBuffer(), list.getCount()); }
+ template<typename T>
+ static Slice<T*> asSlice(const List<ComPtr<T>>& list)
+ {
+ return makeSlice((T* const*)list.getBuffer(), list.getCount());
+ }
- /// Get a list as a slice
- template <typename T>
- static Slice<T> asSlice(const List<T>& list) { return Slice<T>(list.getBuffer(), list.getCount()); }
+ /// Get a list as a slice
+ template<typename T>
+ static Slice<T> asSlice(const List<T>& list)
+ {
+ return Slice<T>(list.getBuffer(), list.getCount());
+ }
- template <typename T>
+ template<typename T>
static List<ComPtr<T>> toComPtrList(const Slice<T*>& in)
{
ISlangUnknown* check = (T*)nullptr;
SLANG_UNUSED(check);
List<ComPtr<T>> list;
list.setCount(in.count);
- for (Index i = 0; i < in.count; ++i) list[i] = ComPtr<T>(in[i]);
+ for (Index i = 0; i < in.count; ++i)
+ list[i] = ComPtr<T>(in[i]);
return list;
}
private:
-
/*
- A reason to wrap in a struct rather than have as free functions is doing so will lead to compile time
- errors with incorrect usage around temporaries.
+ A reason to wrap in a struct rather than have as free functions is doing so will lead to compile
+ time errors with incorrect usage around temporaries.
*/
/// We don't want to make a temporary list into a slice..
- template <typename T>
+ template<typename T>
static Slice<T> asSlice(const List<T>&& list) = delete;
// We don't want temporaries to be 'asSliced' so disable
static TerminatedCharSlice asTerminatedCharSlice(const String&& in) = delete;
@@ -78,7 +91,7 @@ SLANG_FORCE_INLINE CharSlice asCharSlice(const UnownedStringSlice& slice)
SLANG_FORCE_INLINE String asString(const CharSlice& slice)
{
- return String(slice.begin(), slice.end());
+ return String(slice.begin(), slice.end());
}
struct SliceAllocator
@@ -87,21 +100,24 @@ struct SliceAllocator
TerminatedCharSlice allocate(const UnownedStringSlice& slice);
TerminatedCharSlice allocate(const String& in) { return allocate(in.getUnownedSlice()); }
TerminatedCharSlice allocate(const char* in);
- TerminatedCharSlice allocate(const char* start, const char* end) { return allocate(UnownedStringSlice(start, end)); }
+ TerminatedCharSlice allocate(const char* start, const char* end)
+ {
+ return allocate(UnownedStringSlice(start, end));
+ }
Slice<TerminatedCharSlice> allocate(const List<String>& in);
- /// Get the backing arena
+ /// Get the backing arena
MemoryArena& getArena() { return m_arena; }
void deallocateAll() { m_arena.deallocateAll(); }
- SliceAllocator():
- m_arena(2097152)
+ SliceAllocator()
+ : m_arena(2097152)
{
}
+
protected:
-
MemoryArena m_arena;
};