mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 01:26:15 +02:00
add HAVE_BOEHMGC guards to batched allocation functions
This commit is contained in:
parent
8e2eaaaf69
commit
4d629c4f7a
2 changed files with 11 additions and 4 deletions
|
@ -42,6 +42,7 @@ inline void * allocBytes(size_t n)
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
Value * EvalState::allocValue()
|
Value * EvalState::allocValue()
|
||||||
{
|
{
|
||||||
|
#if HAVE_BOEHMGC
|
||||||
/* We use the boehm batch allocator to speed up allocations of Values (of which there are many).
|
/* We use the boehm batch allocator to speed up allocations of Values (of which there are many).
|
||||||
GC_malloc_many returns a linked list of objects of the given size, where the first word
|
GC_malloc_many returns a linked list of objects of the given size, where the first word
|
||||||
of each object is also the pointer to the next object in the list. This also means that we
|
of each object is also the pointer to the next object in the list. This also means that we
|
||||||
|
@ -56,6 +57,9 @@ Value * EvalState::allocValue()
|
||||||
void * p = *valueAllocCache;
|
void * p = *valueAllocCache;
|
||||||
*valueAllocCache = GC_NEXT(p);
|
*valueAllocCache = GC_NEXT(p);
|
||||||
GC_NEXT(p) = nullptr;
|
GC_NEXT(p) = nullptr;
|
||||||
|
#else
|
||||||
|
void * p = allocBytes(sizeof(Value));
|
||||||
|
#endif
|
||||||
|
|
||||||
nrValues++;
|
nrValues++;
|
||||||
return (Value *) p;
|
return (Value *) p;
|
||||||
|
@ -70,9 +74,8 @@ Env & EvalState::allocEnv(size_t size)
|
||||||
|
|
||||||
Env * env;
|
Env * env;
|
||||||
|
|
||||||
if (size != 1)
|
#if HAVE_BOEHMGC
|
||||||
env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *));
|
if (size == 1) {
|
||||||
else {
|
|
||||||
/* see allocValue for explanations. */
|
/* see allocValue for explanations. */
|
||||||
if (!*env1AllocCache) {
|
if (!*env1AllocCache) {
|
||||||
*env1AllocCache = GC_malloc_many(sizeof(Env) + sizeof(Value *));
|
*env1AllocCache = GC_malloc_many(sizeof(Env) + sizeof(Value *));
|
||||||
|
@ -83,7 +86,9 @@ Env & EvalState::allocEnv(size_t size)
|
||||||
*env1AllocCache = GC_NEXT(p);
|
*env1AllocCache = GC_NEXT(p);
|
||||||
GC_NEXT(p) = nullptr;
|
GC_NEXT(p) = nullptr;
|
||||||
env = (Env *) p;
|
env = (Env *) p;
|
||||||
}
|
} else
|
||||||
|
#endif
|
||||||
|
env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *));
|
||||||
|
|
||||||
env->type = Env::Plain;
|
env->type = Env::Plain;
|
||||||
|
|
||||||
|
|
|
@ -133,11 +133,13 @@ private:
|
||||||
/* Cache used by prim_match(). */
|
/* Cache used by prim_match(). */
|
||||||
std::shared_ptr<RegexCache> regexCache;
|
std::shared_ptr<RegexCache> regexCache;
|
||||||
|
|
||||||
|
#if HAVE_BOEHMGC
|
||||||
/* Allocation cache for GC'd Value objects. */
|
/* Allocation cache for GC'd Value objects. */
|
||||||
std::shared_ptr<void *> valueAllocCache;
|
std::shared_ptr<void *> valueAllocCache;
|
||||||
|
|
||||||
/* Allocation cache for size-1 Env objects. */
|
/* Allocation cache for size-1 Env objects. */
|
||||||
std::shared_ptr<void *> env1AllocCache;
|
std::shared_ptr<void *> env1AllocCache;
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue