diff options
| author | shadchin <[email protected]> | 2022-02-10 16:44:39 +0300 |
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:44:39 +0300 |
| commit | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch) | |
| tree | 64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Objects/stringlib/join.h | |
| parent | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Objects/stringlib/join.h')
| -rw-r--r-- | contrib/tools/python3/src/Objects/stringlib/join.h | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/contrib/tools/python3/src/Objects/stringlib/join.h b/contrib/tools/python3/src/Objects/stringlib/join.h index 5573924a49c..53bcbdea7ad 100644 --- a/contrib/tools/python3/src/Objects/stringlib/join.h +++ b/contrib/tools/python3/src/Objects/stringlib/join.h @@ -7,8 +7,8 @@ Py_LOCAL_INLINE(PyObject *) STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) { - const char *sepstr = STRINGLIB_STR(sep); - Py_ssize_t seplen = STRINGLIB_LEN(sep); + const char *sepstr = STRINGLIB_STR(sep); + Py_ssize_t seplen = STRINGLIB_LEN(sep); PyObject *res = NULL; char *p; Py_ssize_t seqlen = 0; @@ -18,9 +18,9 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) Py_buffer *buffers = NULL; #define NB_STATIC_BUFFERS 10 Py_buffer static_buffers[NB_STATIC_BUFFERS]; -#define GIL_THRESHOLD 1048576 - int drop_gil = 1; - PyThreadState *save = NULL; +#define GIL_THRESHOLD 1048576 + int drop_gil = 1; + PyThreadState *save = NULL; seq = PySequence_Fast(iterable, "can only join an iterable"); if (seq == NULL) { @@ -68,21 +68,21 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) buffers[i].buf = PyBytes_AS_STRING(item); buffers[i].len = PyBytes_GET_SIZE(item); } - else { - if (PyObject_GetBuffer(item, &buffers[i], PyBUF_SIMPLE) != 0) { - PyErr_Format(PyExc_TypeError, - "sequence item %zd: expected a bytes-like object, " - "%.80s found", - i, Py_TYPE(item)->tp_name); - goto error; - } - /* If the backing objects are mutable, then dropping the GIL - * opens up race conditions where another thread tries to modify - * the object which we hold a buffer on it. Such code has data - * races anyway, but this is a conservative approach that avoids - * changing the behaviour of that data race. - */ - drop_gil = 0; + else { + if (PyObject_GetBuffer(item, &buffers[i], PyBUF_SIMPLE) != 0) { + PyErr_Format(PyExc_TypeError, + "sequence item %zd: expected a bytes-like object, " + "%.80s found", + i, Py_TYPE(item)->tp_name); + goto error; + } + /* If the backing objects are mutable, then dropping the GIL + * opens up race conditions where another thread tries to modify + * the object which we hold a buffer on it. Such code has data + * races anyway, but this is a conservative approach that avoids + * changing the behaviour of that data race. + */ + drop_gil = 0; } nbufs = i + 1; /* for error cleanup */ itemlen = buffers[i].len; @@ -114,12 +114,12 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) /* Catenate everything. */ p = STRINGLIB_STR(res); - if (sz < GIL_THRESHOLD) { - drop_gil = 0; /* Benefits are likely outweighed by the overheads */ - } - if (drop_gil) { - save = PyEval_SaveThread(); - } + if (sz < GIL_THRESHOLD) { + drop_gil = 0; /* Benefits are likely outweighed by the overheads */ + } + if (drop_gil) { + save = PyEval_SaveThread(); + } if (!seplen) { /* fast path */ for (i = 0; i < nbufs; i++) { @@ -129,23 +129,23 @@ STRINGLIB(bytes_join)(PyObject *sep, PyObject *iterable) p += n; } } - else { - for (i = 0; i < nbufs; i++) { - Py_ssize_t n; - char *q; - if (i) { - memcpy(p, sepstr, seplen); - p += seplen; - } - n = buffers[i].len; - q = buffers[i].buf; - memcpy(p, q, n); - p += n; + else { + for (i = 0; i < nbufs; i++) { + Py_ssize_t n; + char *q; + if (i) { + memcpy(p, sepstr, seplen); + p += seplen; + } + n = buffers[i].len; + q = buffers[i].buf; + memcpy(p, q, n); + p += n; } } - if (drop_gil) { - PyEval_RestoreThread(save); - } + if (drop_gil) { + PyEval_RestoreThread(save); + } goto done; error: @@ -160,4 +160,4 @@ done: } #undef NB_STATIC_BUFFERS -#undef GIL_THRESHOLD +#undef GIL_THRESHOLD |
