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

Method JSObjectKeysProxy_isDisjoint

src/JSObjectKeysProxy.cc:318–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

316}
317
318PyObject *JSObjectKeysProxyMethodDefinitions::JSObjectKeysProxy_isDisjoint(JSObjectKeysProxy *self, PyObject *other) {
319 PyObject *it;
320 PyObject *item = NULL;
321
322 Py_ssize_t selfLen = JSObjectKeysProxyMethodDefinitions::JSObjectKeysProxy_length(self);
323
324 if ((PyObject *)self == other) {
325 if (selfLen == 0) {
326 Py_RETURN_TRUE;
327 }
328 else {
329 Py_RETURN_FALSE;
330 }
331 }
332
333 /* Iterate over the shorter object (only if other is a set,
334 * because PySequence_Contains may be expensive otherwise): */
335 if (PyAnySet_Check(other) || PyDictViewSet_Check(other)) {
336 Py_ssize_t len_self = selfLen;
337 Py_ssize_t len_other = PyObject_Size(other);
338 if (len_other == -1) {
339 return NULL;
340 }
341
342 if ((len_other > len_self)) {
343 PyObject *tmp = other;
344 other = (PyObject *)self;
345 self = (JSObjectKeysProxy *)tmp;
346 }
347 }
348
349 it = PyObject_GetIter(other);
350 if (it == NULL) {
351 return NULL;
352 }
353
354 while ((item = PyIter_Next(it)) != NULL) {
355 int contains;
356 if (PyObject_TypeCheck(self, &JSObjectKeysProxyType)) {
357 contains = JSObjectKeysProxyMethodDefinitions::JSObjectKeysProxy_contains(self, item);
358 }
359 else {
360 contains = PySequence_Contains((PyObject *)self, item);
361 }
362 Py_DECREF(item);
363 if (contains == -1) {
364 Py_DECREF(it);
365 return NULL;
366 }
367
368 if (contains) {
369 Py_DECREF(it);
370 Py_RETURN_FALSE;
371 }
372 }
373
374 Py_DECREF(it);
375 if (PyErr_Occurred()) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected