From e4a785a071942f754156a5778f5949a1d7eaedca Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Wed, 25 Mar 2015 07:45:29 -0700 Subject: [PATCH] Remove oldSize from allocate API. binary_trees - wren .......... 0.29s 0.0048 107.79% relative to baseline delta_blue - wren .......... 0.12s 0.0017 106.95% relative to baseline fib - wren .......... 0.30s 0.0042 119.95% relative to baseline for - wren .......... 0.12s 0.0020 107.57% relative to baseline method_call - wren .......... 0.15s 0.0256 106.09% relative to baseline map_numeric - wren .......... 0.44s 0.0199 105.27% relative to baseline map_string - wren .......... 0.14s 0.0049 100.18% relative to baseline string_equals - wren .......... 0.30s 0.0032 100.57% relative to baseline Thanks, Michel! --- script/benchmark.py | 2 +- src/include/wren.h | 21 ++++++++++----------- src/vm/wren_vm.c | 13 +++---------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/script/benchmark.py b/script/benchmark.py index b96ac66c..d3867240 100755 --- a/script/benchmark.py +++ b/script/benchmark.py @@ -264,7 +264,7 @@ def read_baseline(): benchmark[2] = float(best) -def generate_baseline(graph): +def generate_baseline(): print("generating baseline") baseline_text = "" for benchmark in BENCHMARKS: diff --git a/src/include/wren.h b/src/include/wren.h index eb0dd651..b32b883e 100644 --- a/src/include/wren.h +++ b/src/include/wren.h @@ -14,20 +14,19 @@ typedef struct WrenMethod WrenMethod; // A generic allocation function that handles all explicit memory management // used by Wren. It's used like so: // -// - To allocate new memory, [memory] is NULL and [oldSize] is zero. It should -// return the allocated memory or NULL on failure. +// - To allocate new memory, [memory] is NULL and [newSize] is the desired +// size. It should return the allocated memory or NULL on failure. // -// - To attempt to grow an existing allocation, [memory] is the memory, -// [oldSize] is its previous size, and [newSize] is the desired size. -// It should return [memory] if it was able to grow it in place, or a new -// pointer if it had to move it. +// - To attempt to grow an existing allocation, [memory] is the memory, and +// [newSize] is the desired size. It should return [memory] if it was able to +// grow it in place, or a new pointer if it had to move it. // -// - To shrink memory, [memory], [oldSize], and [newSize] are the same as above -// but it will always return [memory]. +// - To shrink memory, [memory] and [newSize] are the same as above but it will +// always return [memory]. // -// - To free memory, [memory] will be the memory to free and [newSize] and -// [oldSize] will be zero. It should return NULL. -typedef void* (*WrenReallocateFn)(void* memory, size_t oldSize, size_t newSize); +// - To free memory, [memory] will be the memory to free and [newSize] will be +// zero. It should return NULL. +typedef void* (*WrenReallocateFn)(void* memory, size_t newSize); // A function callable from Wren code, but implemented in C. typedef void (*WrenForeignMethodFn)(WrenVM* vm); diff --git a/src/vm/wren_vm.c b/src/vm/wren_vm.c index 1e4c9279..7f7068f5 100644 --- a/src/vm/wren_vm.c +++ b/src/vm/wren_vm.c @@ -18,22 +18,15 @@ #include #endif -// The built-in reallocation function used when one is not provided by the -// configuration. -static void* defaultReallocate(void* memory, size_t oldSize, size_t newSize) -{ - return realloc(memory, newSize); -} - WrenVM* wrenNewVM(WrenConfiguration* configuration) { - WrenReallocateFn reallocate = defaultReallocate; + WrenReallocateFn reallocate = realloc; if (configuration->reallocateFn != NULL) { reallocate = configuration->reallocateFn; } - WrenVM* vm = (WrenVM*)reallocate(NULL, 0, sizeof(*vm)); + WrenVM* vm = (WrenVM*)reallocate(NULL, sizeof(*vm)); memset(vm, 0, sizeof(WrenVM)); vm->reallocate = reallocate; @@ -209,7 +202,7 @@ void* wrenReallocate(WrenVM* vm, void* memory, size_t oldSize, size_t newSize) if (newSize > 0 && vm->bytesAllocated > vm->nextGC) collectGarbage(vm); #endif - return vm->reallocate(memory, oldSize, newSize); + return vm->reallocate(memory, newSize); } // Captures the local variable [local] into an [Upvalue]. If that local is