Skip to content

Commit b2cb6b1

Browse files
committed
remove indirection
1 parent c390a03 commit b2cb6b1

File tree

5 files changed

+27
-34
lines changed

5 files changed

+27
-34
lines changed

Include/internal/pycore_bytesobject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ extern PyObject* _PyBytes_FormatEx(
1414
PyObject *args,
1515
int use_bytearray);
1616

17+
/* Concatenate two bytes objects. Used as the sq_concat slot and by the
18+
* specializing interpreter. Unlike PyBytes_Concat(), this returns a new
19+
* reference rather than modifying its first argument in place. */
20+
extern PyObject* _PyBytes_Concat(PyObject *a, PyObject *b);
21+
1722
extern PyObject* _PyBytes_FromHex(
1823
PyObject *string,
1924
int use_bytearray);

Include/internal/pycore_dict.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ typedef struct {
8787
extern PyDictKeysObject *_PyDict_NewKeysForClass(PyHeapTypeObject *);
8888
extern PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *);
8989

90+
/* Implementations of the `|` and `|=` operators for dict, used by the
91+
* specializing interpreter. */
92+
extern PyObject *_PyDict_Or(PyObject *self, PyObject *other);
93+
extern PyObject *_PyDict_IOr(PyObject *self, PyObject *other);
94+
9095
/* Gets a version number unique to the current state of the keys of dict, if possible.
9196
* Returns the version number, or zero if it was not possible to get a version number. */
9297
extern uint32_t _PyDictKeys_GetVersionForCurrentState(

Objects/bytesobject.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,9 +1536,9 @@ bytes_length(PyObject *self)
15361536
return Py_SIZE(a);
15371537
}
15381538

1539-
/* This is also used by PyBytes_Concat() */
1540-
static PyObject *
1541-
bytes_concat(PyObject *a, PyObject *b)
1539+
/* This is also used by PyBytes_Concat() and the specializing interpreter. */
1540+
PyObject *
1541+
_PyBytes_Concat(PyObject *a, PyObject *b)
15421542
{
15431543
Py_buffer va, vb;
15441544
PyObject *result = NULL;
@@ -1804,7 +1804,7 @@ bytes_buffer_getbuffer(PyObject *op, Py_buffer *view, int flags)
18041804

18051805
static PySequenceMethods bytes_as_sequence = {
18061806
bytes_length, /*sq_length*/
1807-
bytes_concat, /*sq_concat*/
1807+
_PyBytes_Concat, /*sq_concat*/
18081808
bytes_repeat, /*sq_repeat*/
18091809
bytes_item, /*sq_item*/
18101810
0, /*sq_slice*/
@@ -3294,7 +3294,7 @@ PyBytes_Concat(PyObject **pv, PyObject *w)
32943294
else {
32953295
/* Multiple references, need to create new object */
32963296
PyObject *v;
3297-
v = bytes_concat(*pv, w);
3297+
v = _PyBytes_Concat(*pv, w);
32983298
Py_SETREF(*pv, v);
32993299
}
33003300
}

Objects/dictobject.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5041,8 +5041,8 @@ dict___sizeof___impl(PyDictObject *self)
50415041
return PyLong_FromSsize_t(_PyDict_SizeOf(self));
50425042
}
50435043

5044-
static PyObject *
5045-
dict_or(PyObject *self, PyObject *other)
5044+
PyObject *
5045+
_PyDict_Or(PyObject *self, PyObject *other)
50465046
{
50475047
if (!PyAnyDict_Check(self) || !PyAnyDict_Check(other)) {
50485048
Py_RETURN_NOTIMPLEMENTED;
@@ -5077,12 +5077,12 @@ frozendict_or(PyObject *self, PyObject *other)
50775077
}
50785078
}
50795079

5080-
return dict_or(self, other);
5080+
return _PyDict_Or(self, other);
50815081
}
50825082

50835083

5084-
static PyObject *
5085-
dict_ior(PyObject *self, PyObject *other)
5084+
PyObject *
5085+
_PyDict_IOr(PyObject *self, PyObject *other)
50865086
{
50875087
if (dict_update_arg(self, other)) {
50885088
return NULL;
@@ -5198,8 +5198,8 @@ static PySequenceMethods dict_as_sequence = {
51985198
};
51995199

52005200
static PyNumberMethods dict_as_number = {
5201-
.nb_or = dict_or,
5202-
.nb_inplace_or = dict_ior,
5201+
.nb_or = _PyDict_Or,
5202+
.nb_inplace_or = _PyDict_IOr,
52035203
};
52045204

52055205
static PyObject *

Python/specialize.c

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "opcode.h"
44

5+
#include "pycore_bytesobject.h" // _PyBytes_Concat
56
#include "pycore_code.h"
67
#include "pycore_critical_section.h"
78
#include "pycore_descrobject.h" // _PyMethodWrapper_Type
@@ -2166,24 +2167,6 @@ int_tuple_multiply(PyObject *lhs, PyObject *rhs)
21662167
return seq_int_multiply(rhs, lhs, PyTuple_Type.tp_as_sequence->sq_repeat);
21672168
}
21682169

2169-
static PyObject *
2170-
bytes_bytes_add(PyObject *lhs, PyObject *rhs)
2171-
{
2172-
return PyBytes_Type.tp_as_sequence->sq_concat(lhs, rhs);
2173-
}
2174-
2175-
static PyObject *
2176-
dict_dict_or(PyObject *lhs, PyObject *rhs)
2177-
{
2178-
return PyDict_Type.tp_as_number->nb_or(lhs, rhs);
2179-
}
2180-
2181-
static PyObject *
2182-
dict_dict_ior(PyObject *lhs, PyObject *rhs)
2183-
{
2184-
return PyDict_Type.tp_as_number->nb_inplace_or(lhs, rhs);
2185-
}
2186-
21872170
static int
21882171
compactlongs_guard(PyObject *lhs, PyObject *rhs)
21892172
{
@@ -2311,8 +2294,8 @@ static _PyBinaryOpSpecializationDescr binaryop_extend_descrs[] = {
23112294

23122295
/* bytes + bytes: bytes_concat may return an operand when one side
23132296
is empty, so result is not always unique. */
2314-
{NB_ADD, NULL, bytes_bytes_add, &PyBytes_Type, 0, &PyBytes_Type, &PyBytes_Type},
2315-
{NB_INPLACE_ADD, NULL, bytes_bytes_add, &PyBytes_Type, 0, &PyBytes_Type, &PyBytes_Type},
2297+
{NB_ADD, NULL, _PyBytes_Concat, &PyBytes_Type, 0, &PyBytes_Type, &PyBytes_Type},
2298+
{NB_INPLACE_ADD, NULL, _PyBytes_Concat, &PyBytes_Type, 0, &PyBytes_Type, &PyBytes_Type},
23162299

23172300
/* bytes * int / int * bytes: call bytes_repeat directly.
23182301
bytes_repeat returns the original when n == 1. */
@@ -2329,8 +2312,8 @@ static _PyBinaryOpSpecializationDescr binaryop_extend_descrs[] = {
23292312
{NB_INPLACE_MULTIPLY, NULL, int_tuple_multiply, &PyTuple_Type, 0, &PyLong_Type, &PyTuple_Type},
23302313

23312314
/* dict | dict */
2332-
{NB_OR, NULL, dict_dict_or, &PyDict_Type, 1, &PyDict_Type, &PyDict_Type},
2333-
{NB_INPLACE_OR, NULL, dict_dict_ior, &PyDict_Type, 0, &PyDict_Type, &PyDict_Type},
2315+
{NB_OR, NULL, _PyDict_Or, &PyDict_Type, 1, &PyDict_Type, &PyDict_Type},
2316+
{NB_INPLACE_OR, NULL, _PyDict_IOr, &PyDict_Type, 0, &PyDict_Type, &PyDict_Type},
23342317
};
23352318

23362319
static int

0 commit comments

Comments
 (0)