Skip to content

Commit 209350e

Browse files
committed
Merge pull request #980 from undingen/pyxl2_2
Misc pyxl2 perf improvements continued
2 parents 045a427 + 9c5f498 commit 209350e

File tree

7 files changed

+37
-16
lines changed

7 files changed

+37
-16
lines changed

from_cpython/Include/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ struct _typeobject {
456456

457457
void* _hcls;
458458
void* _hcattrs;
459-
char _ics[32];
459+
char _ics[40];
460460
void* _gcvisit_func;
461461
int _attrs_offset;
462462
char _flags[7]; // These are bools in C++

from_cpython/Objects/unicodeobject.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7221,15 +7221,20 @@ old replaced by new. If the optional argument count is\n\
72217221
given, only the first count occurrences are replaced.");
72227222

72237223
static PyObject*
7224-
unicode_replace(PyUnicodeObject *self, PyObject *args)
7224+
// Pyston change: don't use varags calling convention
7225+
// unicode_replace(PyUnicodeObject *self, PyObject *args)
7226+
unicode_replace(PyUnicodeObject *self, PyUnicodeObject *str1, PyUnicodeObject* str2, PyObject** args)
72257227
{
7226-
PyUnicodeObject *str1;
7227-
PyUnicodeObject *str2;
7228+
PyObject* _maxcount = args[0];
72287229
Py_ssize_t maxcount = -1;
72297230
PyObject *result;
72307231

7231-
if (!PyArg_ParseTuple(args, "OO|n:replace", &str1, &str2, &maxcount))
7232+
// Pyston change: don't use varags calling convention
7233+
// if (!PyArg_ParseTuple(args, "OO|n:replace", &str1, &str2, &maxcount))
7234+
// return NULL;
7235+
if (_maxcount && !PyArg_ParseSingle(_maxcount, 3, "replace", "n", &maxcount))
72327236
return NULL;
7237+
72337238
str1 = (PyUnicodeObject *)PyUnicode_FromObject((PyObject *)str1);
72347239
if (str1 == NULL)
72357240
return NULL;
@@ -7832,7 +7837,7 @@ unicode_getnewargs(PyUnicodeObject *v)
78327837

78337838
static PyMethodDef unicode_methods[] = {
78347839
{"encode", (PyCFunction) unicode_encode, METH_VARARGS | METH_KEYWORDS, encode__doc__},
7835-
{"replace", (PyCFunction) unicode_replace, METH_VARARGS, replace__doc__},
7840+
{"replace", (PyCFunction) unicode_replace, METH_O3 | METH_D1, replace__doc__},
78367841
{"split", (PyCFunction) unicode_split, METH_VARARGS, split__doc__},
78377842
{"rsplit", (PyCFunction) unicode_rsplit, METH_VARARGS, rsplit__doc__},
78387843
{"join", (PyCFunction) unicode_join, METH_O, join__doc__},

src/capi/typeobject.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,24 +1014,26 @@ Box* slotTpGetattrHookInternal(Box* self, BoxedString* name, GetattrRewriteArgs*
10141014
return res;
10151015
} else if (return_convention == ReturnConvention::NO_RETURN) {
10161016
assert(!res);
1017-
} else if (return_convention == ReturnConvention::CAPI_RETURN) {
1017+
} else if (return_convention == ReturnConvention::CAPI_RETURN
1018+
|| return_convention == ReturnConvention::NOEXC_POSSIBLE) {
10181019
// If we get a CAPI return, we probably did a function call, and these guards
10191020
// will probably just make the rewrite fail:
10201021
if (res) {
10211022
rtn->addGuardNotEq(0);
10221023
rewrite_args->setReturn(rtn, ReturnConvention::HAS_RETURN);
10231024
return res;
1024-
} else
1025-
rtn->addGuard(0);
1025+
} else {
1026+
// this could set a CAPI exception and we won't clear it inside the rewrite.
1027+
rewrite_args = 0;
1028+
}
10261029
} else {
1027-
assert(return_convention == ReturnConvention::NOEXC_POSSIBLE);
1028-
rewrite_args = NULL;
1030+
RELEASE_ASSERT(0, "");
10291031
}
10301032
}
10311033
} else {
10321034
try {
10331035
assert(!PyType_Check(self)); // There would be a getattribute
1034-
res = getattrInternalGeneric<false, rewritable>(self, name, NULL, false, false, NULL, NULL);
1036+
res = getattrInternalGeneric<false, NOT_REWRITABLE>(self, name, NULL, false, false, NULL, NULL);
10351037
} catch (ExcInfo e) {
10361038
if (!e.matches(AttributeError)) {
10371039
if (S == CAPI) {

src/runtime/list.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,6 @@ void setupList() {
12731273
static PyMappingMethods list_as_mapping;
12741274
list_cls->tp_as_mapping = &list_as_mapping;
12751275

1276-
list_cls->tp_iter = listIter;
12771276
list_iterator_cls = BoxedClass::create(type_cls, object_cls, &BoxedListIterator::gcHandler, 0, 0,
12781277
sizeof(BoxedListIterator), false, "listiterator");
12791278
list_reverse_iterator_cls = BoxedClass::create(type_cls, object_cls, &BoxedListIterator::gcHandler, 0, 0,
@@ -1356,6 +1355,7 @@ void setupList() {
13561355

13571356
list_cls->giveAttr("__hash__", None);
13581357
list_cls->freeze();
1358+
list_cls->tp_iter = listIter;
13591359

13601360
list_cls->tp_as_sequence->sq_length = list_length;
13611361
list_cls->tp_as_sequence->sq_concat = (binaryfunc)list_concat;

src/runtime/objmodel.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5729,8 +5729,7 @@ Box* getiter(Box* o) {
57295729
if (PyType_HasFeature(type, Py_TPFLAGS_HAVE_ITER) && type->tp_iter != slot_tp_iter && type->tp_iter) {
57305730
r = type->tp_iter(o);
57315731
} else {
5732-
static BoxedString* iter_str = internStringImmortal("__iter__");
5733-
r = callattrInternal0<CXX, NOT_REWRITABLE>(o, iter_str, LookupScope::CLASS_ONLY, NULL, ArgPassSpec(0));
5732+
r = type->callIterIC(o);
57345733
}
57355734
if (r) {
57365735
if (!PyIter_Check(r)) {

src/runtime/types.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,20 @@ Box* BoxedClass::callReprIC(Box* obj) {
290290
return ic->call(obj, repr_str, callattr_flags, nullptr, nullptr, nullptr, nullptr, nullptr);
291291
}
292292

293+
Box* BoxedClass::callIterIC(Box* obj) {
294+
assert(obj->cls == this);
295+
296+
auto ic = iter_ic.get();
297+
if (!ic) {
298+
ic = new CallattrIC();
299+
iter_ic.reset(ic);
300+
}
301+
302+
static BoxedString* iter_str = internStringImmortal("__iter__");
303+
CallattrFlags callattr_flags{.cls_only = true, .null_on_nonexistent = true, .argspec = ArgPassSpec(0) };
304+
return ic->call(obj, iter_str, callattr_flags, nullptr, nullptr, nullptr, nullptr, nullptr);
305+
}
306+
293307
bool BoxedClass::callNonzeroIC(Box* obj) {
294308
assert(obj->cls == this);
295309

src/runtime/types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,12 @@ class BoxedClass : public BoxVar {
194194

195195
// TODO: these don't actually get deallocated right now
196196
std::unique_ptr<CallattrCapiIC> next_ic;
197-
std::unique_ptr<CallattrIC> hasnext_ic, repr_ic;
197+
std::unique_ptr<CallattrIC> hasnext_ic, repr_ic, iter_ic;
198198
std::unique_ptr<NonzeroIC> nonzero_ic;
199199
Box* callHasnextIC(Box* obj, bool null_on_nonexistent);
200200
Box* call_nextIC(Box* obj) noexcept;
201201
Box* callReprIC(Box* obj);
202+
Box* callIterIC(Box* obj);
202203
bool callNonzeroIC(Box* obj);
203204

204205
gcvisit_func gc_visit;

0 commit comments

Comments
 (0)