| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 66363b9 commit 93930ea
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -759,13 +759,17 @@ m_log10(double x) | |||
| 759 | 759 | static PyObject * | |
| 760 | 760 | math_gcd(PyObject *module, PyObject * const *args, Py_ssize_t nargs) | |
| 761 | 761 | { | |
| 762 | - PyObject *res, *x; | ||
| 763 | - Py_ssize_t i; | ||
| 762 | + // Fast-path for the common case: gcd(int, int) | ||
| 763 | + if (nargs == 2 && PyLong_CheckExact(args[0]) && PyLong_CheckExact(args[1])) | ||
| 764 | + { | ||
| 765 | + return _PyLong_GCD(args[0], args[1]); | ||
| 766 | + } | ||
| 764 | 767 | ||
| 765 | 768 | if (nargs == 0) { | |
| 766 | 769 | return PyLong_FromLong(0); | |
| 767 | 770 | } | |
| 768 | - res = PyNumber_Index(args[0]); | ||
| 771 | + | ||
| 772 | + PyObject *res = PyNumber_Index(args[0]); | ||
| 769 | 773 | if (res == NULL) { | |
| 770 | 774 | return NULL; | |
| 771 | 775 | } | |
@@ -775,8 +779,8 @@ math_gcd(PyObject *module, PyObject * const *args, Py_ssize_t nargs) | |||
| 775 | 779 | } | |
| 776 | 780 | ||
| 777 | 781 | PyObject *one = _PyLong_GetOne(); // borrowed ref | |
| 778 | - for (i = 1; i < nargs; i++) { | ||
| 779 | - x = _PyNumber_Index(args[i]); | ||
| 782 | + for (Py_ssize_t i = 1; i < nargs; i++) { | ||
| 783 | + PyObject *x = _PyNumber_Index(args[i]); | ||
| 780 | 784 | if (x == NULL) { | |
| 781 | 785 | Py_DECREF(res); | |
| 782 | 786 | return NULL; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments