Skip to content

Commit ec07466

Browse files
gh-159191: Explain the bytes shortcut in the buffer cleanup loop
Also move the fast path comment next to the check it describes.
1 parent 6794be4 commit ec07466

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎Objects/stringlib/join.h‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ STRINGLIB(bytes_join_lock_held)(PyObject *sep, PyObject *seq)
3535
}
3636
#endif
3737

38-
/* Fast path: all items are exact bytes and the result is too small to
39-
* release the GIL for. Nothing here runs Python code or suspends the
40-
* critical section, so seq keeps the items alive and they can be copied
41-
* without taking references. */
4238
Py_ssize_t limit = GIL_THRESHOLD - seplen;
4339
for (i = 0; i < seqlen; i++) {
4440
item = PySequence_Fast_GET_ITEM(seq, i);
@@ -48,6 +44,10 @@ STRINGLIB(bytes_join_lock_held)(PyObject *sep, PyObject *seq)
4844
}
4945
sz += PyBytes_GET_SIZE(item) + seplen;
5046
}
47+
/* Fast path: all items are exact bytes and the result is too small to
48+
* release the GIL for. Nothing here runs Python code or suspends the
49+
* critical section, so seq keeps the items alive and they can be copied
50+
* without taking references. */
5151
if (i == seqlen) {
5252
res = STRINGLIB_NEW(NULL, sz - seplen);
5353
if (res == NULL) {
@@ -189,7 +189,8 @@ STRINGLIB(bytes_join_lock_held)(PyObject *sep, PyObject *seq)
189189
for (i = 0; i < nbufs; i++) {
190190
PyObject *obj = buffers[i].obj;
191191
if (obj != NULL && PyBytes_CheckExact(obj)) {
192-
/* bytes has no bf_releasebuffer */
192+
/* Same as PyBuffer_Release(), without the call: bytes has no
193+
* bf_releasebuffer, so only the reference to obj is dropped. */
193194
Py_DECREF(obj);
194195
}
195196
else {

0 commit comments

Comments
 (0)