CORE: ensure that the allocator was initialized successfully

master
Martin Gerhardy 2022-05-18 07:12:22 +02:00
parent 88f6ca67a5
commit fcd1ba859f
1 changed files with 4 additions and 4 deletions

View File

@ -78,7 +78,7 @@ public:
Map(std::initializer_list<KeyValue> other, int maxSize = 4096) {
core_assert_msg(maxSize > 0, "Max size must be greater than 0 - but is %i", maxSize);
core_assert_msg(maxSize >= (int)other.size(), "Max size must be greater than the initializer list: %i vs %i", maxSize, (int)other.size());
_allocator.init(core_max(2, maxSize));
core_assert_always(_allocator.init(core_max(2, maxSize)));
_buckets.fill(nullptr);
for (auto i = other.begin(); i != other.end(); ++i) {
put(i->key, i->value);
@ -86,11 +86,11 @@ public:
}
Map(int maxSize = 4096) {
core_assert_msg(maxSize > 0, "Max size must be greater than 0 - but is %i", maxSize);
_allocator.init(core_max(2, maxSize));
core_assert_always(_allocator.init(core_max(2, maxSize)));
_buckets.fill(nullptr);
}
Map(const Map& other) {
_allocator.init((other._allocator.max)());
core_assert_always(_allocator.init((other._allocator.max)()));
_buckets.fill(nullptr);
for (auto i = other.begin(); i != other.end(); ++i) {
put(i->key, i->value);
@ -120,7 +120,7 @@ public:
Map& operator=(const Map& other) {
clear();
_allocator.shutdown(); // TODO: not needed init() will handle this
_allocator.init((other._allocator.max)());
core_assert_always(_allocator.init((other._allocator.max)()));
_buckets.fill(nullptr);
for (auto i = other.begin(); i != other.end(); ++i) {
put(i->key, i->value);