Skip to content

Commit 7705e2a

Browse files
committed
refactor: reuse PYXXH*_do_update helpers in vectorcall functions
Replace duplicated Py_BEGIN_ALLOW_THREADS/update/Py_END_ALLOW_THREADS/ PyBuffer_Release blocks with calls to existing PYXXH*_do_update helpers. Reduces code duplication across all four vectorcall implementations.
1 parent 9f40c56 commit 7705e2a

1 file changed

Lines changed: 8 additions & 24 deletions

File tree

src/_xxhash.c

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,8 @@ PYXXH32_vectorcall(PyObject *type, PyObject *const *args,
527527
self->seed = seed;
528528
XXH32_reset(self->xxhash_state, seed);
529529

530-
if (buf.buf) {
531-
Py_BEGIN_ALLOW_THREADS
532-
XXH32_update(self->xxhash_state, buf.buf, buf.len);
533-
Py_END_ALLOW_THREADS
534-
PyBuffer_Release(&buf);
535-
}
530+
if (buf.buf)
531+
PYXXH32_do_update(self, &buf);
536532
Py_XDECREF(buf_owner);
537533
return (PyObject *)self;
538534
}
@@ -890,12 +886,8 @@ PYXXH64_vectorcall(PyObject *type, PyObject *const *args,
890886
self->seed = seed;
891887
XXH64_reset(self->xxhash_state, seed);
892888

893-
if (buf.buf) {
894-
Py_BEGIN_ALLOW_THREADS
895-
XXH64_update(self->xxhash_state, buf.buf, buf.len);
896-
Py_END_ALLOW_THREADS
897-
PyBuffer_Release(&buf);
898-
}
889+
if (buf.buf)
890+
PYXXH64_do_update(self, &buf);
899891
Py_XDECREF(buf_owner);
900892
return (PyObject *)self;
901893
}
@@ -1249,12 +1241,8 @@ PYXXH3_64_vectorcall(PyObject *type, PyObject *const *args,
12491241
self->seed = seed;
12501242
XXH3_64bits_reset_withSeed(self->xxhash_state, seed);
12511243

1252-
if (buf.buf) {
1253-
Py_BEGIN_ALLOW_THREADS
1254-
XXH3_64bits_update(self->xxhash_state, buf.buf, buf.len);
1255-
Py_END_ALLOW_THREADS
1256-
PyBuffer_Release(&buf);
1257-
}
1244+
if (buf.buf)
1245+
PYXXH3_64_do_update(self, &buf);
12581246
Py_XDECREF(buf_owner);
12591247
return (PyObject *)self;
12601248
}
@@ -1617,12 +1605,8 @@ PYXXH3_128_vectorcall(PyObject *type, PyObject *const *args,
16171605
self->seed = seed;
16181606
XXH3_128bits_reset_withSeed(self->xxhash_state, seed);
16191607

1620-
if (buf.buf) {
1621-
Py_BEGIN_ALLOW_THREADS
1622-
XXH3_128bits_update(self->xxhash_state, buf.buf, buf.len);
1623-
Py_END_ALLOW_THREADS
1624-
PyBuffer_Release(&buf);
1625-
}
1608+
if (buf.buf)
1609+
PYXXH3_128_do_update(self, &buf);
16261610
Py_XDECREF(buf_owner);
16271611
return (PyObject *)self;
16281612
}

0 commit comments

Comments
 (0)