author | Terrence Cole <terrence@mozilla.com> |
Tue, 08 Nov 2011 14:54:57 -0800 | |
changeset 80651 | 646f4a4d58eadad66b17f5e11daa0ac5e7271d40 |
parent 80650 | 2c13341cc1c1565189d147a3af9921a3a919f056 |
child 80652 | b2e8d10f25a1fd4cba7fed248ce8059b5070dfe1 |
push id | 3543 |
push user | tcole@mozilla.com |
push date | Tue, 22 Nov 2011 22:24:58 +0000 |
treeherder | mozilla-inbound@646f4a4d58ea [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | Waldo |
bugs | 696232 |
milestone | 11.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/js/src/jsarray.cpp +++ b/js/src/jsarray.cpp @@ -1765,26 +1765,32 @@ InitArrayTypes(JSContext *cx, TypeObject continue; Type valtype = GetValueType(cx, vector[i]); types->addType(cx, valtype); } } return true; } -static JSBool -InitArrayElements(JSContext *cx, JSObject *obj, jsuint start, jsuint count, const Value *vector, bool updateTypes) +enum ShouldUpdateTypes +{ + UpdateTypes = true, + DontUpdateTypes = false +}; + +static bool +InitArrayElements(JSContext *cx, JSObject *obj, uint32 start, uint32 count, const Value *vector, ShouldUpdateTypes updateTypes) { JS_ASSERT(count <= MAX_ARRAY_INDEX); if (count == 0) - return JS_TRUE; + return true; if (updateTypes && !InitArrayTypes(cx, obj->getType(cx), vector, count)) - return JS_FALSE; + return false; /* * Optimize for dense arrays so long as adding the given set of elements * wouldn't otherwise make the array slow. */ do { if (!obj->isDenseArray()) break; @@ -1807,41 +1813,41 @@ InitArrayElements(JSContext *cx, JSObjec JS_ASSERT_IF(count != 0, !obj->getDenseArrayElement(newlen - 1).isMagic(JS_ARRAY_HOLE)); return true; } while (false); const Value* end = vector + count; while (vector < end && start <= MAX_ARRAY_INDEX) { if (!JS_CHECK_OPERATION_LIMIT(cx) || !SetArrayElement(cx, obj, start++, *vector++)) { - return JS_FALSE; + return false; } } if (vector == end) - return JS_TRUE; + return true; /* Finish out any remaining elements past the max array index. */ if (obj->isDenseArray() && !obj->makeDenseArraySlow(cx)) - return JS_FALSE; + return false; JS_ASSERT(start == MAX_ARRAY_INDEX + 1); AutoValueRooter tvr(cx); AutoIdRooter idr(cx); Value idval = DoubleValue(MAX_ARRAY_INDEX + 1); do { *tvr.addr() = *vector++; if (!js_ValueToStringId(cx, idval, idr.addr()) || !obj->setGeneric(cx, idr.id(), tvr.addr(), true)) { - return JS_FALSE; + return false; } idval.getDoubleRef() += 1; } while (vector != end); - return JS_TRUE; + return true; } #if 0 static JSBool InitArrayObject(JSContext *cx, JSObject *obj, jsuint length, const Value *vector) { JS_ASSERT(obj->isArray()); @@ -2235,17 +2241,17 @@ js::array_sort(JSContext *cx, uintN argc } /* * We no longer need to root the scratch space for the merge sort, so * unroot it now to make the job of a potential GC under * InitArrayElements easier. */ vec.resize(n); - if (!InitArrayElements(cx, obj, 0, jsuint(n), vec.begin(), false)) + if (!InitArrayElements(cx, obj, 0, jsuint(n), vec.begin(), DontUpdateTypes)) return false; } /* Set undefs that sorted after the rest of elements. */ while (undefs != 0) { --undefs; if (!JS_CHECK_OPERATION_LIMIT(cx) || !SetArrayElement(cx, obj, n++, UndefinedValue())) return false; @@ -2265,17 +2271,17 @@ js::array_sort(JSContext *cx, uintN argc */ static bool array_push_slowly(JSContext *cx, JSObject *obj, CallArgs &args) { jsuint length; if (!js_GetLengthProperty(cx, obj, &length)) return false; - if (!InitArrayElements(cx, obj, length, args.length(), args.array(), true)) + if (!InitArrayElements(cx, obj, length, args.length(), args.array(), UpdateTypes)) return false; /* Per ECMA-262, return the new array length. */ jsdouble newlength = length + jsdouble(args.length()); args.rval().setNumber(newlength); return js_SetLengthProperty(cx, obj, newlength); } @@ -2549,17 +2555,17 @@ array_unshift(JSContext *cx, uintN argc, !SetOrDeleteArrayElement(cx, obj, upperIndex, hole, tvr.value())) { return JS_FALSE; } } while (last != 0); } } /* Copy from args to the bottom of the array. */ - if (!InitArrayElements(cx, obj, 0, args.length(), args.array(), true)) + if (!InitArrayElements(cx, obj, 0, args.length(), args.array(), UpdateTypes)) return JS_FALSE; newlen += args.length(); } if (!js_SetLengthProperty(cx, obj, newlen)) return JS_FALSE; /* Follow Perl by returning the new array length. */