MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / JSArrayProxy_richcompare

Method JSArrayProxy_richcompare

src/JSArrayProxy.cc:417–512  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

415}
416
417PyObject *JSArrayProxyMethodDefinitions::JSArrayProxy_richcompare(JSArrayProxy *self, PyObject *other, int op)
418{
419 if (!PyList_Check(self) || !PyList_Check(other)) {
420 Py_RETURN_NOTIMPLEMENTED;
421 }
422
423 if (self == (JSArrayProxy *)other && (op == Py_EQ || op == Py_NE)) {
424 if (op == Py_EQ) {
425 Py_RETURN_TRUE;
426 }
427 else {
428 Py_RETURN_FALSE;
429 }
430 }
431
432 Py_ssize_t selfLength = JSArrayProxy_length(self);
433 Py_ssize_t otherLength;
434
435 if (PyObject_TypeCheck(other, &JSArrayProxyType)) {
436 otherLength = JSArrayProxy_length((JSArrayProxy *)other);
437 } else {
438 otherLength = Py_SIZE(other);
439 }
440
441 if (selfLength != otherLength && (op == Py_EQ || op == Py_NE)) {
442 /* Shortcut: if the lengths differ, the lists differ */
443 if (op == Py_EQ) {
444 Py_RETURN_FALSE;
445 }
446 else {
447 Py_RETURN_TRUE;
448 }
449 }
450
451 JS::RootedValue elementVal(GLOBAL_CX);
452
453 Py_ssize_t index;
454 /* Search for the first index where items are different */
455 for (index = 0; index < selfLength && index < otherLength; index++) {
456 JS_GetElement(GLOBAL_CX, *(self->jsArray), index, &elementVal);
457
458 PyObject *leftItem = pyTypeFactory(GLOBAL_CX, elementVal);
459 PyObject *rightItem;
460
461 bool needToDecRefRightItem;
462 if (PyObject_TypeCheck(other, &JSArrayProxyType)) {
463 JS_GetElement(GLOBAL_CX, *(((JSArrayProxy *)other)->jsArray), index, &elementVal);
464 rightItem = pyTypeFactory(GLOBAL_CX, elementVal);
465 needToDecRefRightItem = true;
466 } else {
467 rightItem = ((PyListObject *)other)->ob_item[index];
468 needToDecRefRightItem = false;
469 }
470
471 if (leftItem == rightItem) {
472 continue;
473 }
474

Callers

nothing calls this directly

Calls 1

pyTypeFactoryFunction · 0.85

Tested by

no test coverage detected