Skip to content

Commit 1f6a09f

Browse files
authored
gh-100239: Specialize more binary operations using BINARY_OP_EXTEND (GH-128956)
1 parent 9d38143 commit 1f6a09f

21 files changed

+1852
-1226
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_code.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,11 @@ typedef struct {
503503
aliased to either operand). Used by the tier 2 optimizer to enable
504504
inplace follow-up ops. */
505505
int result_unique;
506+
/* Expected types of the left and right operands. Used by the tier 2
507+
optimizer to eliminate _GUARD_BINARY_OP_EXTEND when the operand
508+
types are already known. NULL means unknown/don't eliminate. */
509+
PyTypeObject *lhs_type;
510+
PyTypeObject *rhs_type;
506511
} _PyBinaryOpSpecializationDescr;
507512

508513
/* Comparison bit masks. */

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(

Include/internal/pycore_list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern "C" {
1515
PyAPI_FUNC(PyObject*) _PyList_Extend(PyListObject *, PyObject *);
1616
PyAPI_FUNC(PyObject) *_PyList_SliceSubscript(PyObject*, PyObject*);
1717
PyAPI_FUNC(PyObject *) _PyList_BinarySlice(PyObject *, PyObject *, PyObject *);
18+
PyAPI_FUNC(PyObject *) _PyList_Concat(PyObject *, PyObject *);
1819
extern void _PyList_DebugMallocStats(FILE *out);
1920
// _PyList_GetItemRef should be used only when the object is known as a list
2021
// because it doesn't raise TypeError when the object is not a list, whereas PyList_GetItemRef does.

Include/internal/pycore_tuple.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ PyAPI_FUNC(void) _PyStolenTuple_Free(PyObject *self);
2828
PyAPI_FUNC(PyObject *)_PyTuple_FromStackRefStealOnSuccess(const union _PyStackRef *, Py_ssize_t);
2929
PyAPI_FUNC(PyObject *)_PyTuple_FromArraySteal(PyObject *const *, Py_ssize_t);
3030
PyAPI_FUNC(PyObject *) _PyTuple_BinarySlice(PyObject *, PyObject *, PyObject *);
31+
PyAPI_FUNC(PyObject *) _PyTuple_Concat(PyObject *, PyObject *);
3132

3233
PyAPI_FUNC(PyObject *) _PyTuple_FromPair(PyObject *, PyObject *);
3334
PyAPI_FUNC(PyObject *) _PyTuple_FromPairSteal(PyObject *, PyObject *);

0 commit comments

Comments
 (0)