1
0
forked from Mirror/wren

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!
This commit is contained in:
Bob Nystrom
2015-03-25 07:45:29 -07:00
parent 8c4e5eeea8
commit e4a785a071
3 changed files with 14 additions and 22 deletions

View File

@ -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:

View File

@ -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);

View File

@ -18,22 +18,15 @@
#include <time.h>
#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