return vr;
}
-static void vecrealloc(struct naVec* v)
+static void resize(struct naVec* v)
{
struct VecRec* vr = newvecrec(v->rec);
naGC_swapfree((void**)&(v->rec), vr);
naRef naVec_get(naRef v, int i)
{
if(IS_VEC(v)) {
- struct VecRec* r = v.ref.ptr.vec->rec;
+ struct VecRec* r = PTR(v).vec->rec;
if(r) {
if(i < 0) i += r->size;
if(i >= 0 && i < r->size) return r->array[i];
void naVec_set(naRef vec, int i, naRef o)
{
if(IS_VEC(vec)) {
- struct VecRec* r = vec.ref.ptr.vec->rec;
+ struct VecRec* r = PTR(vec).vec->rec;
if(r && i >= r->size) return;
r->array[i] = o;
}
int naVec_size(naRef v)
{
if(IS_VEC(v)) {
- struct VecRec* r = v.ref.ptr.vec->rec;
+ struct VecRec* r = PTR(v).vec->rec;
return r ? r->size : 0;
}
return 0;
int naVec_append(naRef vec, naRef o)
{
if(IS_VEC(vec)) {
- struct VecRec* r = vec.ref.ptr.vec->rec;
+ struct VecRec* r = PTR(vec).vec->rec;
while(!r || r->size >= r->alloced) {
- vecrealloc(vec.ref.ptr.vec);
- r = vec.ref.ptr.vec->rec;
+ resize(PTR(vec).vec);
+ r = PTR(vec).vec->rec;
}
r->array[r->size] = o;
return r->size++;
void naVec_setsize(naRef vec, int sz)
{
int i;
- struct VecRec* v = vec.ref.ptr.vec->rec;
+ struct VecRec* v = PTR(vec).vec->rec;
struct VecRec* nv = naAlloc(sizeof(struct VecRec) + sizeof(naRef) * sz);
nv->size = sz;
nv->alloced = sz;
for(i=0; i<sz; i++)
nv->array[i] = (v && i < v->size) ? v->array[i] : naNil();
- naFree(v);
- vec.ref.ptr.vec->rec = nv;
+ naGC_swapfree((void**)&(PTR(vec).vec->rec), nv);
}
naRef naVec_removelast(naRef vec)
{
naRef o;
if(IS_VEC(vec)) {
- struct VecRec* v = vec.ref.ptr.vec->rec;
+ struct VecRec* v = PTR(vec).vec->rec;
if(!v || v->size == 0) return naNil();
o = v->array[v->size - 1];
v->size--;
if(v->size < (v->alloced >> 1))
- vecrealloc(vec.ref.ptr.vec);
+ resize(PTR(vec).vec);
return o;
}
return naNil();