Skip to content

Commit 19582fb

Browse files
committed
Use pg_VectorCoordsFromObj in _vector(2|3)_set
Rather than using pgVectorCompatible_Check and then PySequence_AsVectorCoords, which have duplicative operations, we can use pg_VectorCoordsFromObj to try to unpack directly for a speedup when processing sequence input.
1 parent eaf3aa0 commit 19582fb

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src_c/math.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,13 +2340,8 @@ static int
23402340
_vector2_set(pgVector *self, PyObject *xOrSequence, PyObject *y)
23412341
{
23422342
if (xOrSequence) {
2343-
if (pgVectorCompatible_Check(xOrSequence, self->dim)) {
2344-
if (!PySequence_AsVectorCoords(xOrSequence, self->coords, 2)) {
2345-
return -1;
2346-
}
2347-
else {
2348-
return 0;
2349-
}
2343+
if (pg_VectorCoordsFromObj(xOrSequence, 2, self->coords)) {
2344+
return 0;
23502345
}
23512346
else if (RealNumber_Check(xOrSequence)) {
23522347
self->coords[0] = PyFloat_AsDouble(xOrSequence);
@@ -2788,13 +2783,8 @@ static int
27882783
_vector3_set(pgVector *self, PyObject *xOrSequence, PyObject *y, PyObject *z)
27892784
{
27902785
if (xOrSequence) {
2791-
if (pgVectorCompatible_Check(xOrSequence, self->dim)) {
2792-
if (!PySequence_AsVectorCoords(xOrSequence, self->coords, 3)) {
2793-
return -1;
2794-
}
2795-
else {
2796-
return 0;
2797-
}
2786+
if (pg_VectorCoordsFromObj(xOrSequence, 3, self->coords)) {
2787+
return 0;
27982788
}
27992789
else if (RealNumber_Check(xOrSequence)) {
28002790
self->coords[0] = PyFloat_AsDouble(xOrSequence);

0 commit comments

Comments
 (0)