TEST(hash_slot, move) { json::hash_slot<int> slot1 (10); json::hash_slot<int> slot2 (std::move(slot1)); assert_equal(slot1.status, json::hash_slot<int>::free); assert_equal(slot2.status, json::hash_slot<int>::busy); assert_equal(slot2.value(), 10); }
TEST(hash_slot, copy) { json::hash_slot<int> slot1 (10); json::hash_slot<int> slot2 (slot1); assert_equal(slot1.status, json::hash_slot<int>::busy); assert_equal(slot2.status, json::hash_slot<int>::busy); assert_equal(slot1.value(), 10); assert_equal(slot2.value(), 10); }
TEST(hash_slot, swap) { json::hash_slot<int> slot1 (10); json::hash_slot<int> slot2 (20); assert_equal(slot1.status, json::hash_slot<int>::busy); assert_equal(slot2.status, json::hash_slot<int>::busy); assert_equal(slot1.value(), 10); assert_equal(slot2.value(), 20); std::swap(slot1, slot2); assert_equal(slot1.status, json::hash_slot<int>::busy); assert_equal(slot2.status, json::hash_slot<int>::busy); assert_equal(slot1.value(), 20); assert_equal(slot2.value(), 10); }
void QObjectBenchmark::signal_slot_benchmark() { QFETCH(int, type); Object singleObject; Object multiObject; Functor functor; singleObject.setObjectName("single"); multiObject.setObjectName("multi"); if (type == 5) { QObject::connect(&singleObject, &Object::signal0, functor); } else if (type == 4) { QObject::connect(&singleObject, &Object::signal0, &singleObject, &Object::slot0); } else { singleObject.connect(&singleObject, SIGNAL(signal0()), SLOT(slot0())); } multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(slot0())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal1())); multiObject.connect(&multiObject, SIGNAL(signal1()), SLOT(slot1())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal2())); multiObject.connect(&multiObject, SIGNAL(signal2()), SLOT(slot2())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal3())); multiObject.connect(&multiObject, SIGNAL(signal3()), SLOT(slot3())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal4())); multiObject.connect(&multiObject, SIGNAL(signal4()), SLOT(slot4())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal5())); multiObject.connect(&multiObject, SIGNAL(signal5()), SLOT(slot5())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal6())); multiObject.connect(&multiObject, SIGNAL(signal6()), SLOT(slot6())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal7())); multiObject.connect(&multiObject, SIGNAL(signal7()), SLOT(slot7())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal8())); multiObject.connect(&multiObject, SIGNAL(signal8()), SLOT(slot8())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal9())); multiObject.connect(&multiObject, SIGNAL(signal9()), SLOT(slot9())); if (type == 0) { QBENCHMARK { singleObject.slot0(); } } else if (type == 1) {
void QObjectBenchmark::signal_slot_benchmark() { QFETCH(int, type); Object singleObject; Object multiObject; singleObject.setObjectName(QLatin1String("single")); multiObject.setObjectName(QLatin1String("multi")); singleObject.connect(&singleObject, SIGNAL(signal0()), SLOT(slot0())); multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(slot0())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal1())); multiObject.connect(&multiObject, SIGNAL(signal1()), SLOT(slot1())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal2())); multiObject.connect(&multiObject, SIGNAL(signal2()), SLOT(slot2())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal3())); multiObject.connect(&multiObject, SIGNAL(signal3()), SLOT(slot3())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal4())); multiObject.connect(&multiObject, SIGNAL(signal4()), SLOT(slot4())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal5())); multiObject.connect(&multiObject, SIGNAL(signal5()), SLOT(slot5())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal6())); multiObject.connect(&multiObject, SIGNAL(signal6()), SLOT(slot6())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal7())); multiObject.connect(&multiObject, SIGNAL(signal7()), SLOT(slot7())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal8())); multiObject.connect(&multiObject, SIGNAL(signal8()), SLOT(slot8())); // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal9())); multiObject.connect(&multiObject, SIGNAL(signal9()), SLOT(slot9())); if (type == 0) { QBENCHMARK { singleObject.slot0(); } } else if (type == 1) {
NUITKA_MAY_BE_UNUSED static PyObject *BINARY_OPERATION_REMAINDER( PyObject *operand1, PyObject *operand2 ) { CHECK_OBJECT( operand1 ); CHECK_OBJECT( operand2 ); binaryfunc slot1 = NULL; binaryfunc slot2 = NULL; PyTypeObject *type1 = Py_TYPE( operand1 ); PyTypeObject *type2 = Py_TYPE( operand2 ); if ( type1->tp_as_number != NULL && NEW_STYLE_NUMBER( operand1 ) ) { slot1 = type1->tp_as_number->nb_remainder; } if ( type1 != type2 ) { if ( type2->tp_as_number != NULL && NEW_STYLE_NUMBER( operand2 ) ) { slot2 = type2->tp_as_number->nb_remainder; if ( slot1 == slot2 ) { slot2 = NULL; } } } if ( slot1 != NULL ) { if ( slot2 && PyType_IsSubtype( type2, type1 ) ) { PyObject *x = slot2( operand1, operand2 ); if ( x != Py_NotImplemented ) { if (unlikely( x == NULL )) { return NULL; } return x; } Py_DECREF( x ); slot2 = NULL; } PyObject *x = slot1( operand1, operand2 ); if ( x != Py_NotImplemented ) { if (unlikely( x == NULL )) { return NULL; } return x; } Py_DECREF( x ); } if ( slot2 != NULL ) { PyObject *x = slot2( operand1, operand2 ); if ( x != Py_NotImplemented ) { if (unlikely( x == NULL )) { return NULL; } return x; } Py_DECREF( x ); } #if PYTHON_VERSION < 300 if ( !NEW_STYLE_NUMBER( operand1 ) || !NEW_STYLE_NUMBER( operand2 ) ) { int err = PyNumber_CoerceEx( &operand1, &operand2 ); if ( err < 0 ) { return NULL; } if ( err == 0 ) { PyNumberMethods *mv = Py_TYPE( operand1 )->tp_as_number; if ( mv ) { binaryfunc slot = mv->nb_remainder; if ( slot != NULL ) { PyObject *x = slot( operand1, operand2 ); Py_DECREF( operand1 ); Py_DECREF( operand2 ); if (unlikely( x == NULL )) { return NULL; } return x; } } // CoerceEx did that Py_DECREF( operand1 ); Py_DECREF( operand2 ); } } #endif PyErr_Format( PyExc_TypeError, "unsupported operand type(s) for %%: '%s' and '%s'", type1->tp_name, type2->tp_name ); return NULL; }
NUITKA_MAY_BE_UNUSED static PyObject *BINARY_OPERATION_ADD( PyObject *operand1, PyObject *operand2 ) { CHECK_OBJECT( operand1 ); CHECK_OBJECT( operand2 ); #if PYTHON_VERSION < 300 // Something similar for Python3 should exist too. if ( PyInt_CheckExact( operand1 ) && PyInt_CheckExact( operand2 ) ) { long a, b, i; a = PyInt_AS_LONG( operand1 ); b = PyInt_AS_LONG( operand2 ); i = a + b; // Detect overflow, in which case, a "long" object would have to be // created, which we won't handle here. if (likely(!( (i^a) < 0 && (i^b) < 0 ) )) { return PyInt_FromLong( i ); } } #endif binaryfunc slot1 = NULL; binaryfunc slot2 = NULL; PyTypeObject *type1 = Py_TYPE( operand1 ); PyTypeObject *type2 = Py_TYPE( operand2 ); if ( type1->tp_as_number != NULL && NEW_STYLE_NUMBER( operand1 ) ) { slot1 = type1->tp_as_number->nb_add; } if ( type1 != type2 ) { if ( type2->tp_as_number != NULL && NEW_STYLE_NUMBER( operand2 ) ) { slot2 = type2->tp_as_number->nb_add; if ( slot1 == slot2 ) { slot2 = NULL; } } } if ( slot1 != NULL ) { if ( slot2 && PyType_IsSubtype( type2, type1 ) ) { PyObject *x = slot2( operand1, operand2 ); if ( x != Py_NotImplemented ) { if (unlikely( x == NULL )) { return NULL; } return x; } Py_DECREF( x ); slot2 = NULL; } PyObject *x = slot1( operand1, operand2 ); if ( x != Py_NotImplemented ) { if (unlikely( x == NULL )) { return NULL; } return x; } Py_DECREF( x ); } if ( slot2 != NULL ) { PyObject *x = slot2( operand1, operand2 ); if ( x != Py_NotImplemented ) { if (unlikely( x == NULL )) { return NULL; } return x; } Py_DECREF( x ); } #if PYTHON_VERSION < 300 if ( !NEW_STYLE_NUMBER( operand1 ) || !NEW_STYLE_NUMBER( operand2 ) ) { int err = PyNumber_CoerceEx( &operand1, &operand2 ); if ( err < 0 ) { return NULL; } if ( err == 0 ) { PyNumberMethods *mv = Py_TYPE( operand1 )->tp_as_number; if ( mv ) { binaryfunc slot = mv->nb_add; if ( slot != NULL ) { PyObject *x = slot( operand1, operand2 ); Py_DECREF( operand1 ); Py_DECREF( operand2 ); if (unlikely( x == NULL )) { return NULL; } return x; } } // CoerceEx did that Py_DECREF( operand1 ); Py_DECREF( operand2 ); } } #endif // Special case for "+", also works as sequence concat. PySequenceMethods *seq_methods = Py_TYPE( operand1 )->tp_as_sequence; if ( seq_methods && seq_methods->sq_concat ) { PyObject *result = (*seq_methods->sq_concat)( operand1, operand2 ); if (unlikely( result == NULL )) { return NULL; } return result; } PyErr_Format( PyExc_TypeError, "unsupported operand type(s) for +: '%s' and '%s'", type1->tp_name, type2->tp_name ); return NULL; }
NUITKA_MAY_BE_UNUSED static PyObject *BINARY_OPERATION_MUL( PyObject *operand1, PyObject *operand2 ) { CHECK_OBJECT( operand1 ); CHECK_OBJECT( operand2 ); binaryfunc slot1 = NULL; binaryfunc slot2 = NULL; PyTypeObject *type1 = Py_TYPE( operand1 ); PyTypeObject *type2 = Py_TYPE( operand2 ); if ( type1->tp_as_number != NULL && NEW_STYLE_NUMBER( operand1 ) ) { slot1 = type1->tp_as_number->nb_multiply; } if ( type1 != type2 ) { if ( type2->tp_as_number != NULL && NEW_STYLE_NUMBER( operand2 ) ) { slot2 = type2->tp_as_number->nb_multiply; if ( slot1 == slot2 ) { slot2 = NULL; } } } if ( slot1 != NULL ) { if ( slot2 && PyType_IsSubtype( type2, type1 ) ) { PyObject *x = slot2( operand1, operand2 ); if ( x != Py_NotImplemented ) { if (unlikely( x == NULL )) { return NULL; } return x; } Py_DECREF( x ); slot2 = NULL; } PyObject *x = slot1( operand1, operand2 ); if ( x != Py_NotImplemented ) { if (unlikely( x == NULL )) { return NULL; } return x; } Py_DECREF( x ); } if ( slot2 != NULL ) { PyObject *x = slot2( operand1, operand2 ); if ( x != Py_NotImplemented ) { if (unlikely( x == NULL )) { return NULL; } return x; } Py_DECREF( x ); } #if PYTHON_VERSION < 300 if ( !NEW_STYLE_NUMBER( operand1 ) || !NEW_STYLE_NUMBER( operand2 ) ) { int err = PyNumber_CoerceEx( &operand1, &operand2 ); if ( err < 0 ) { return NULL; } if ( err == 0 ) { PyNumberMethods *mv = Py_TYPE( operand1 )->tp_as_number; if ( mv ) { binaryfunc slot = mv->nb_multiply; if ( slot != NULL ) { PyObject *x = slot( operand1, operand2 ); Py_DECREF( operand1 ); Py_DECREF( operand2 ); if (unlikely( x == NULL )) { return NULL; } return x; } } // CoerceEx did that Py_DECREF( operand1 ); Py_DECREF( operand2 ); } } #endif // Special case for "+", also works as sequence concat. PySequenceMethods *seq_methods1 = Py_TYPE( operand1 )->tp_as_sequence; PySequenceMethods *seq_methods2 = Py_TYPE( operand2 )->tp_as_sequence; if ( seq_methods1 != NULL && seq_methods1->sq_repeat ) { return SEQUENCE_REPEAT( seq_methods1->sq_repeat, operand1, operand2 ); } if ( seq_methods2 != NULL && seq_methods2->sq_repeat ) { return SEQUENCE_REPEAT( seq_methods2->sq_repeat, operand2, operand1 ); } PyErr_Format( PyExc_TypeError, "unsupported operand type(s) for *: '%s' and '%s'", type1->tp_name, type2->tp_name ); return NULL; }