summaryrefslogtreecommitdiff
path: root/source/core/slang-list.h
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-07-06 11:58:14 -0700
committerGitHub <noreply@github.com>2020-07-06 11:58:14 -0700
commitcf62f13cdc8a7f21c78f03b097bff6edf09fdead (patch)
tree6a08ddcd4dfe39976a7dec29164da4f7b87ddfda /source/core/slang-list.h
parentffd0b9c9b06a22d886c77d777d9aa0cd1298d363 (diff)
ShortList<T> and core.natvis improvements. (#1430)
* ShortList<T> and core.natvis improvements. * Fix gcc build. * add `getBuffer()` accessor to `GetArrayViewResult`
Diffstat (limited to 'source/core/slang-list.h')
-rw-r--r--source/core/slang-list.h73
1 files changed, 7 insertions, 66 deletions
diff --git a/source/core/slang-list.h b/source/core/slang-list.h
index 28180ce4f..5c1e3cbc7 100644
--- a/source/core/slang-list.h
+++ b/source/core/slang-list.h
@@ -14,72 +14,6 @@
namespace Slang
{
-
- template<typename T, int isPOD>
- class Initializer
- {
-
- };
-
- template<typename T>
- class Initializer<T, 0>
- {
- public:
- static void initialize(T* buffer, int size)
- {
- for (int i = 0; i<size; i++)
- new (buffer + i) T();
- }
- };
- template<typename T>
- class Initializer<T, 1>
- {
- public:
- static void initialize(T* buffer, int size)
- {
- // It's pod so no initialization required
- //for (int i = 0; i < size; i++)
- // new (buffer + i) T;
- }
- };
-
- template<typename T, typename TAllocator>
- class AllocateMethod
- {
- public:
- static inline T* allocateArray(Index count)
- {
- TAllocator allocator;
- T * rs = (T*)allocator.allocate(count * sizeof(T));
- Initializer<T, std::is_pod<T>::value>::initialize(rs, count);
- return rs;
- }
- static inline void deallocateArray(T* ptr, Index count)
- {
- TAllocator allocator;
- if (!std::is_trivially_destructible<T>::value)
- {
- for (Index i = 0; i < count; i++)
- ptr[i].~T();
- }
- allocator.deallocate(ptr);
- }
- };
-
- template<typename T>
- class AllocateMethod<T, StandardAllocator>
- {
- public:
- static inline T* allocateArray(Index count)
- {
- return new T[count];
- }
- static inline void deallocateArray(T* ptr, Index /*bufferSize*/)
- {
- delete [] ptr;
- }
- };
-
// List is container of values of a type held consecutively in memory (much like std::vector)
//
// Note that in this implementation, the underlying memory is backed via an allocation of T[capacity]
@@ -102,6 +36,7 @@ namespace Slang
}
template<typename... Args>
List(const T& val, Args... args)
+ : m_buffer(nullptr), m_count(0), m_capacity(0)
{
_init(val, args...);
}
@@ -611,6 +546,10 @@ namespace Slang
{
return AllocateMethod<T, TAllocator>::allocateArray(count);
}
+ static void _free(T* buffer, Index count)
+ {
+ return AllocateMethod<T, TAllocator>::deallocateArray(buffer, count);
+ }
template<typename... Args>
void _init(const T& val, Args... args)
@@ -618,6 +557,8 @@ namespace Slang
add(val);
_init(args...);
}
+
+ void _init() {}
};
template<typename T>