static int growArray(Ejs *ejs, EjsArray *ap, int len) { EjsObj **dp; ssize size, factor, count; int i; assert(ap); if (len <= 0) { return 0; } if (len <= ap->length) { return 0; } size = mprGetBlockSize(ap->data); size = (int) (mprGetBlockSize(ap->data) / sizeof(EjsObj*)); /* Allocate or grow the data structures. */ if (len > size) { if (size > EJS_LOTSA_PROP) { /* Looks like a big object so grow by a bigger chunk */ factor = max(size / 4, EJS_ROUND_PROP); count = (len + factor) / factor * factor; } else { count = len; } // OPT - this is currently 16 count = EJS_PROP_ROUNDUP(count); if (ap->data == 0) { assert(ap->length == 0); assert(count > 0); if ((ap->data = mprAllocZeroed(sizeof(EjsObj*) * count)) == 0) { return EJS_ERR; } } else { assert(size > 0); if ((ap->data = mprRealloc(ap->data, sizeof(EjsObj*) * count)) == 0) { return EJS_ERR; } } dp = &ap->data[ap->length]; for (i = ap->length; i < count; i++) { *dp++ = ESV(undefined); } } else { mprNop(ITOP(size)); } ap->length = len; return 0; }
static int growArray(Ejs *ejs, EjsArray *ap, int len) { int size, count, factor; mprAssert(ap); if (len <= 0) { return 0; } if (len <= ap->length) { return 0; } size = mprGetBlockSize(ap->data) / (int) sizeof(EjsVar*); /* * Allocate or grow the data structures. */ if (len > size) { if (size > EJS_LOTSA_PROP) { /* * Looks like a big object so grow by a bigger chunk */ factor = max(size / 4, EJS_NUM_PROP); count = (len + factor) / factor * factor; } else { count = len; } count = EJS_PROP_ROUNDUP(count); if (ap->data == 0) { mprAssert(ap->length == 0); mprAssert(count > 0); ap->data = (EjsVar**) mprAllocZeroed(ap, (int) sizeof(EjsVar*) * count); if (ap->data == 0) { return EJS_ERR; } } else { mprAssert(size > 0); ap->data = (EjsVar**) mprRealloc(ap, ap->data, (int) sizeof(EjsVar*) * count); if (ap->data == 0) { return EJS_ERR; } ejsZeroSlots(ejs, &ap->data[ap->length], (count - ap->length)); } } ap->length = len; return 0; }