Skip to content

Commit 584da82

Browse files
authored
Merge pull request #3458 from Starbuck5/small-vector-optimization
Optimize vector creation/update using pg_VectorCoordsFromObj
2 parents 94f7d37 + 19582fb commit 584da82

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
@@ -2341,13 +2341,8 @@ static int
23412341
_vector2_set(pgVector *self, PyObject *xOrSequence, PyObject *y)
23422342
{
23432343
if (xOrSequence) {
2344-
if (pgVectorCompatible_Check(xOrSequence, self->dim)) {
2345-
if (!PySequence_AsVectorCoords(xOrSequence, self->coords, 2)) {
2346-
return -1;
2347-
}
2348-
else {
2349-
return 0;
2350-
}
2344+
if (pg_VectorCoordsFromObj(xOrSequence, 2, self->coords)) {
2345+
return 0;
23512346
}
23522347
else if (RealNumber_Check(xOrSequence)) {
23532348
self->coords[0] = PyFloat_AsDouble(xOrSequence);
@@ -2789,13 +2784,8 @@ static int
27892784
_vector3_set(pgVector *self, PyObject *xOrSequence, PyObject *y, PyObject *z)
27902785
{
27912786
if (xOrSequence) {
2792-
if (pgVectorCompatible_Check(xOrSequence, self->dim)) {
2793-
if (!PySequence_AsVectorCoords(xOrSequence, self->coords, 3)) {
2794-
return -1;
2795-
}
2796-
else {
2797-
return 0;
2798-
}
2787+
if (pg_VectorCoordsFromObj(xOrSequence, 3, self->coords)) {
2788+
return 0;
27992789
}
28002790
else if (RealNumber_Check(xOrSequence)) {
28012791
self->coords[0] = PyFloat_AsDouble(xOrSequence);

0 commit comments

Comments
 (0)