- struct naVec* v = vec.ref.ptr.vec;
- if(!IS_VEC(vec)) return 0;
- if(v->size >= v->alloced)
- realloc(v);
- v->array[v->size] = o;
- return v->size++;
+ if(IS_VEC(vec)) {
+ struct VecRec* r = PTR(vec).vec->rec;
+ while(!r || r->size >= r->alloced) {
+ resize(PTR(vec).vec);
+ r = PTR(vec).vec->rec;
+ }
+ r->array[r->size] = o;
+ return r->size++;
+ }
+ return 0;
+}
+
+void naVec_setsize(naRef vec, int sz)
+{
+ int i;
+ 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();
+ naGC_swapfree((void*)&(PTR(vec).vec->rec), nv);