speed up booting by implementing realloc+padovan

This commit is contained in:
Krasimir Angelov
2022-02-09 10:36:42 +01:00
parent fdd33b63d9
commit 8960e00e26
7 changed files with 159 additions and 11 deletions

View File

@@ -19,7 +19,27 @@ template <class C, class A> inline PGF_INTERNAL
ref<C> vector_new(Vector<A> C::* field, size_t len)
{
ptrdiff_t offset = (ptrdiff_t) &(((C*) NULL)->*field);
ref<C> res = PgfDB::malloc<Vector<A>>(offset+len*sizeof(A)).as_object()-offset;
ref<C> res = PgfDB::malloc<C>(len*sizeof(A)).as_object();
(res->*field).len = len;
return res;
}
PGF_INTERNAL_DECL size_t
get_next_padovan(size_t min);
template <class A> inline PGF_INTERNAL
ref<Vector<A>> vector_resize(ref<Vector<A>> r, size_t len)
{
ref<Vector<A>> res = PgfDB::realloc<Vector<A>>(r,get_next_padovan(len)*sizeof(A)).as_object();
res->len = len;
return res;
}
template <class C, class A> inline PGF_INTERNAL
ref<C> vector_resize(ref<C> r, Vector<A> C::* field, size_t len)
{
ptrdiff_t offset = (ptrdiff_t) &(((C*) NULL)->*field);
ref<C> res = PgfDB::realloc<C>(r,get_next_padovan(len)*sizeof(A)).as_object();
(res->*field).len = len;
return res;
}