fast object iteration (558754, r=brendan, CLOSED TREE).
This commit is contained in:
@@ -5089,70 +5089,6 @@ js_GetXMLMethod(JSContext *cx, JSObject *obj, jsid id, jsval *vp)
|
||||
return ok;
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_EnumerateXMLValues(JSContext *cx, JSObject *obj, JSIterateOp enum_op,
|
||||
jsval *statep, jsid *idp, jsval *vp)
|
||||
{
|
||||
JSXML *xml, *kid;
|
||||
uint32 length, index;
|
||||
JSXMLArrayCursor *cursor;
|
||||
JSObject *kidobj;
|
||||
|
||||
JS_ASSERT(JS_InstanceOf(cx, obj, &js_XMLClass, NULL));
|
||||
xml = (JSXML *) obj->getPrivate();
|
||||
length = JSXML_LENGTH(xml);
|
||||
JS_ASSERT(INT_FITS_IN_JSVAL(length));
|
||||
|
||||
switch (enum_op) {
|
||||
case JSENUMERATE_INIT:
|
||||
if (length == 0) {
|
||||
*statep = JSVAL_ZERO;
|
||||
} else {
|
||||
cursor = cx->create<JSXMLArrayCursor>(&xml->xml_kids);
|
||||
if (!cursor)
|
||||
return JS_FALSE;
|
||||
*statep = PRIVATE_TO_JSVAL(cursor);
|
||||
}
|
||||
JS_ASSERT(!idp);
|
||||
JS_ASSERT(!vp);
|
||||
break;
|
||||
|
||||
case JSENUMERATE_NEXT:
|
||||
if (*statep == JSVAL_ZERO) {
|
||||
*statep = JSVAL_NULL;
|
||||
break;
|
||||
}
|
||||
cursor = (JSXMLArrayCursor *) JSVAL_TO_PRIVATE(*statep);
|
||||
if (cursor && cursor->array && (index = cursor->index) < length) {
|
||||
while (!(kid = XMLARRAY_MEMBER(&xml->xml_kids, index, JSXML))) {
|
||||
if (++index == length)
|
||||
goto destroy;
|
||||
}
|
||||
kidobj = js_GetXMLObject(cx, kid);
|
||||
if (!kidobj)
|
||||
return JS_FALSE;
|
||||
JS_ASSERT(INT_FITS_IN_JSVAL(index));
|
||||
*idp = INT_TO_JSID(index);
|
||||
*vp = OBJECT_TO_JSVAL(kidobj);
|
||||
cursor->index = index + 1;
|
||||
break;
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
|
||||
case JSENUMERATE_DESTROY:
|
||||
if (*statep != JSVAL_ZERO) {
|
||||
cursor = (JSXMLArrayCursor *) JSVAL_TO_PRIVATE(*statep);
|
||||
if (cursor) {
|
||||
destroy:
|
||||
cx->destroy(cursor);
|
||||
}
|
||||
}
|
||||
*statep = JSVAL_NULL;
|
||||
break;
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool
|
||||
js_TestXMLEquality(JSContext *cx, JSObject *obj, jsval v, JSBool *bp)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user