From 2e836481e0d62a876648390a01b08623f8e4602c Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 1 Nov 2013 13:03:29 +0100 Subject: [PATCH] src: remove superfluous memory allocation Fold the heap statistics into the struct Baton, there is no need to allocate memory separately for them. --- src/gc.cc | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/src/gc.cc b/src/gc.cc index 77ba780..86cb86a 100644 --- a/src/gc.cc +++ b/src/gc.cc @@ -35,28 +35,11 @@ QUEUE baton_queue; struct Baton { QUEUE baton_queue; - size_t * stats; // The HeapStatistics Snapshot GCType gcType; GCCallbackFlags gcFlags; - -}; + HeapStatistics stats; -static size_t* getheap() { - - HeapStatistics heap; - - V8::GetHeapStatistics(&heap); - - size_t * stats = new size_t[4]; - - stats[0] = heap.used_heap_size(); - stats[1] = heap.total_heap_size(); - stats[2] = heap.heap_size_limit(); - stats[3] = heap.total_heap_size_executable(); - - return stats; - -} +}; static void after_gc_idle(uv_idle_t*, int) { @@ -72,7 +55,7 @@ static void after_gc_idle(uv_idle_t*, int) { const int argc = 5; Handle argv[argc]; - argv[0] = Integer::New(baton->stats[0]); + argv[0] = Integer::New(baton->stats.used_heap_size()); switch(baton->gcType) { @@ -105,8 +88,6 @@ static void after_gc_idle(uv_idle_t*, int) { argv[3] = Integer::New(baton->gcType); argv[4] = Integer::New(baton->gcFlags); - - delete [] baton->stats; delete baton; afore_callback->Call(afore_context, argc, argv); @@ -121,9 +102,9 @@ static void after_gc(GCType type, GCCallbackFlags flags) { Baton *baton = new Baton(); - baton->stats = getheap(); baton->gcType = type; baton->gcFlags = flags; + V8::GetHeapStatistics(&baton->stats); uv_idle_start(&idle_handle, after_gc_idle); QUEUE_INSERT_TAIL(&baton_queue, &baton->baton_queue);