From 98ceb60eb44766b8c2081fca52047f84508fabfc Mon Sep 17 00:00:00 2001 From: AndreaCatania Date: Wed, 11 Aug 2021 13:09:54 +0200 Subject: Refactors the memnew_placement. With this commit the macro `memnew_placement` uses the standard memory placement syntax: `new (mem) TheClass()`, and removes the outdated and not used syntax: ``` _ALWAYS_INLINE_ void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description) { ``` Thanks to this change, the function `memnew_placement` call is compatible with any class, and can also initialize classes with non-empty constructor: ``` // This is valid, like before. memnew_placement(mem, Variant); // This works too: memnew_placement(mem, Variant(123)); ``` --- core/templates/cowdata.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'core/templates') diff --git a/core/templates/cowdata.h b/core/templates/cowdata.h index c985593473..ba9babe0af 100644 --- a/core/templates/cowdata.h +++ b/core/templates/cowdata.h @@ -232,7 +232,7 @@ uint32_t CowData::_copy_on_write() { uint32_t *mem_new = (uint32_t *)Memory::alloc_static(_get_alloc_size(current_size), true); - new (mem_new - 2, sizeof(uint32_t), "") SafeNumeric(1); //refcount + new (mem_new - 2) SafeNumeric(1); //refcount *(mem_new - 1) = current_size; //size T *_data = (T *)(mem_new); @@ -286,14 +286,14 @@ Error CowData::resize(int p_size) { uint32_t *ptr = (uint32_t *)Memory::alloc_static(alloc_size, true); ERR_FAIL_COND_V(!ptr, ERR_OUT_OF_MEMORY); *(ptr - 1) = 0; //size, currently none - new (ptr - 2, sizeof(uint32_t), "") SafeNumeric(1); //refcount + new (ptr - 2) SafeNumeric(1); //refcount _ptr = (T *)ptr; } else { uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true); ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY); - new (_ptrnew - 2, sizeof(uint32_t), "") SafeNumeric(rc); //refcount + new (_ptrnew - 2) SafeNumeric(rc); //refcount _ptr = (T *)(_ptrnew); } @@ -323,7 +323,7 @@ Error CowData::resize(int p_size) { if (alloc_size != current_alloc_size) { uint32_t *_ptrnew = (uint32_t *)Memory::realloc_static(_ptr, alloc_size, true); ERR_FAIL_COND_V(!_ptrnew, ERR_OUT_OF_MEMORY); - new (_ptrnew - 2, sizeof(uint32_t), "") SafeNumeric(rc); //refcount + new (_ptrnew - 2) SafeNumeric(rc); //refcount _ptr = (T *)(_ptrnew); } -- cgit v1.2.3