refactor: Refactor function _glfw_realloc

Keeps function's original behavior while making the code more readable.
This commit is contained in:
CiroZDP 2025-12-27 19:26:02 +01:00 committed by GitHub
parent dbadda2683
commit ad3d0aa1b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -273,24 +273,23 @@ void* _glfw_calloc(size_t count, size_t size)
void* _glfw_realloc(void* block, size_t size) void* _glfw_realloc(void* block, size_t size)
{ {
if (block && size) if (!block)
{ return _glfw_calloc(1, size);
void* resized = _glfw.allocator.reallocate(block, size, _glfw.allocator.user);
if (resized) if (!size)
return resized;
else
{
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
return NULL;
}
}
else if (block)
{ {
_glfw_free(block); _glfw_free(block);
return NULL; return NULL;
} }
else
return _glfw_calloc(1, size); void* resized = _glfw.allocator.reallocate(block, size, _glfw.allocator.user);
if (!resized)
{
_glfwInputError(GLFW_OUT_OF_MEMORY, NULL);
return NULL;
}
return resized;
} }
void _glfw_free(void* block) void _glfw_free(void* block)