Skip to content

Commit 4a6404a

Browse files
committed
more changes
1 parent cfc8448 commit 4a6404a

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

ZEngine/ZEngine/Core/Container/Array.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ namespace ZEngine::Core::Container
107107

108108
void clear()
109109
{
110-
for (size_type i = 0; i < m_size; ++i)
111-
{
112-
m_data[i].~T();
113-
}
114110
m_size = 0;
115111
}
116112

@@ -152,7 +148,6 @@ namespace ZEngine::Core::Container
152148
{
153149
ZENGINE_VALIDATE_ASSERT(m_size > 0, "Index out of range")
154150
--m_size;
155-
m_data[m_size].~T();
156151
}
157152

158153
~Array()
@@ -171,8 +166,7 @@ namespace ZEngine::Core::Container
171166

172167
size_t old_alloc_size = m_capacity * sizeof(T);
173168
size_t new_alloc_size = new_capacity * sizeof(T);
174-
175-
m_data = static_cast<pointer>(m_allocator->Resize(m_data, old_alloc_size, new_alloc_size, alignof(value_type)));
169+
m_data = static_cast<pointer>(ZENGINE_RESIZE_MEMORY(m_allocator, m_data, old_alloc_size, new_alloc_size, ZENGINE_TYPE_ALIGNMENT(value_type)));
176170
m_capacity = new_capacity;
177171
}
178172

ZEngine/ZEngine/Core/Container/Strings.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@ namespace ZEngine::Core::Container
2020
void init(Memory::ArenaAllocator* allocator, size_type initial_capacity = 16)
2121
{
2222
m_allocator = allocator;
23-
m_size = 0;
24-
m_capacity = 0;
25-
m_data = nullptr;
23+
m_capacity = m_size = 0;
24+
m_data = nullptr;
2625
reserve(initial_capacity);
2726
m_data[0] = '\0';
2827
}
2928

3029
void init(Memory::ArenaAllocator* allocator, const char* str)
3130
{
3231
m_allocator = allocator;
33-
m_size = 0;
34-
m_capacity = 0;
35-
m_data = nullptr;
32+
m_capacity = m_size = 0;
33+
m_data = nullptr;
3634

3735
if (str)
3836
{
@@ -169,7 +167,7 @@ namespace ZEngine::Core::Container
169167
size_t old_alloc_size = m_capacity * sizeof(char);
170168
size_t new_alloc_size = new_capacity * sizeof(char);
171169

172-
m_data = static_cast<pointer>(m_allocator->Resize(m_data, old_alloc_size, new_alloc_size, alignof(value_type)));
170+
m_data = static_cast<pointer>(ZENGINE_RESIZE_MEMORY(m_allocator, m_data, old_alloc_size, new_alloc_size, ZENGINE_TYPE_ALIGNMENT(value_type)));
173171
m_capacity = new_capacity;
174172
}
175173

ZEngine/ZEngine/ZEngineDef.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@
3939
collection.shrink_to_fit(); \
4040
}
4141

42-
#define SINGLE_ARG(...) __VA_ARGS__
42+
#define ZENGINE_RESIZE_MEMORY(allocator, ptr, old_size, new_size, alignment) ((allocator)->Resize((ptr), (old_size), (new_size), (alignment)))
4343

44-
#define MAX_FILE_PATH_COUNT 256
44+
#define ZENGINE_TYPE_ALIGNMENT(type) ((alignof(type) < DEFAULT_ALIGNMENT) ? DEFAULT_ALIGNMENT : alignof(type))
45+
46+
#define SINGLE_ARG(...) __VA_ARGS__
47+
48+
#define MAX_FILE_PATH_COUNT 256
4549

4650
/*
4751
* Allocator and Memory Macros

0 commit comments

Comments
 (0)