- int i, newsz = 1 + ((v->size*3)>>1);
- naRef* na = naAlloc(sizeof(naRef) * newsz);
- v->alloced = newsz;
- for(i=0; i<v->size; i++)
- na[i] = v->array[i];
- naFree(v->array);
- v->array = na;
+ int i, oldsz = old ? old->size : 0, newsz = 1 + ((oldsz*3)>>1);
+ struct VecRec* vr = naAlloc(sizeof(struct VecRec) + sizeof(naRef) * newsz);
+ if(oldsz > newsz) oldsz = newsz; // race protection
+ vr->alloced = newsz;
+ vr->size = oldsz;
+ for(i=0; i<oldsz; i++)
+ vr->array[i] = old->array[i];
+ return vr;