Fast comparison function with type-specific optimizations */
| 15 | |
| 16 | /* Fast comparison function with type-specific optimizations */ |
| 17 | int fast_compare_lt(PyObject *a, PyObject *b) { |
| 18 | /* Fast path for integers */ |
| 19 | if (PyLong_CheckExact(a) && PyLong_CheckExact(b)) { |
| 20 | /* For small integers, use direct comparison */ |
| 21 | long val_a = PyLong_AsLong(a); |
| 22 | long val_b = PyLong_AsLong(b); |
| 23 | if (!PyErr_Occurred()) { |
| 24 | return val_a < val_b ? 1 : 0; |
| 25 | } |
| 26 | PyErr_Clear(); /* Clear error and fall through */ |
| 27 | } |
| 28 | |
| 29 | /* Fast path for strings */ |
| 30 | if (PyUnicode_CheckExact(a) && PyUnicode_CheckExact(b)) { |
| 31 | int result = PyUnicode_Compare(a, b); |
| 32 | if (result != -1 || !PyErr_Occurred()) { |
| 33 | return result < 0 ? 1 : 0; |
| 34 | } |
| 35 | PyErr_Clear(); /* Clear error and fall through */ |
| 36 | } |
| 37 | |
| 38 | /* Fall back to general comparison */ |
| 39 | return PyObject_RichCompareBool(a, b, Py_LT); |
| 40 | } |
| 41 | |
| 42 | /* Fast equality comparison function */ |
| 43 | int fast_compare_eq(PyObject *a, PyObject *b) { |
no outgoing calls
no test coverage detected