mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-10 19:52:50 -06:00
speed up booting by implementing realloc+padovan
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user