Skip to content

Commit 5fbfc0f

Browse files
committed
minor code simplification
1 parent 8f4e7f4 commit 5fbfc0f

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/util/memory_manager.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -322,22 +322,17 @@ void memory::deallocate(void * p) {
322322

323323
void * memory::allocate(size_t s) {
324324
s = s + sizeof(size_t); // we allocate an extra field!
325-
bool out_of_mem = false, counts_exceeded = false;
326325
{
327326
lock_guard lock(*g_memory_mux);
328327
g_memory_alloc_size += s;
329328
g_memory_alloc_count += 1;
330329
if (g_memory_alloc_size > g_memory_max_used_size)
331330
g_memory_max_used_size = g_memory_alloc_size;
332331
if (g_memory_max_size != 0 && g_memory_alloc_size > g_memory_max_size)
333-
out_of_mem = true;
332+
throw_out_of_memory();
334333
if (g_memory_max_alloc_count != 0 && g_memory_alloc_count > g_memory_max_alloc_count)
335-
counts_exceeded = true;
334+
throw_alloc_counts_exceeded();
336335
}
337-
if (out_of_mem)
338-
throw_out_of_memory();
339-
if (counts_exceeded)
340-
throw_alloc_counts_exceeded();
341336
void * r = malloc(s);
342337
if (r == nullptr) {
343338
throw_out_of_memory();
@@ -352,22 +347,17 @@ void* memory::reallocate(void *p, size_t s) {
352347
size_t sz = *sz_p;
353348
void * real_p = reinterpret_cast<void*>(sz_p);
354349
s = s + sizeof(size_t); // we allocate an extra field!
355-
bool out_of_mem = false, counts_exceeded = false;
356350
{
357351
lock_guard lock(*g_memory_mux);
358352
g_memory_alloc_size += s - sz;
359353
g_memory_alloc_count += 1;
360354
if (g_memory_alloc_size > g_memory_max_used_size)
361355
g_memory_max_used_size = g_memory_alloc_size;
362356
if (g_memory_max_size != 0 && g_memory_alloc_size > g_memory_max_size)
363-
out_of_mem = true;
357+
throw_out_of_memory();
364358
if (g_memory_max_alloc_count != 0 && g_memory_alloc_count > g_memory_max_alloc_count)
365-
counts_exceeded = true;
359+
throw_alloc_counts_exceeded();
366360
}
367-
if (out_of_mem)
368-
throw_out_of_memory();
369-
if (counts_exceeded)
370-
throw_alloc_counts_exceeded();
371361
void *r = realloc(real_p, s);
372362
if (r == nullptr) {
373363
throw_out_of_memory();

0 commit comments

Comments
 (0)