Commit 0724433e authored by Kevin Modzelewski's avatar Kevin Modzelewski

More microoptimizations

parent dff9c845
...@@ -3538,13 +3538,12 @@ _pair(Py_ssize_t i1, Py_ssize_t i2) ...@@ -3538,13 +3538,12 @@ _pair(Py_ssize_t i1, Py_ssize_t i2)
} }
static PyObject* static PyObject*
match_span(MatchObject* self, PyObject* args) match_span(MatchObject* self, PyObject* index_)
{ {
Py_ssize_t index; Py_ssize_t index;
PyObject* index_ = Py_False; /* zero */ if (!index_)
if (!PyArg_UnpackTuple(args, "span", 0, 1, &index_)) index_ = Py_False; /* zero */
return NULL;
index = match_getindex(self, index_); index = match_getindex(self, index_);
...@@ -3682,7 +3681,7 @@ static PyMethodDef match_methods[] = { ...@@ -3682,7 +3681,7 @@ static PyMethodDef match_methods[] = {
{"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc}, {"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc},
{"start", (PyCFunction) match_start, METH_VARARGS, match_start_doc}, {"start", (PyCFunction) match_start, METH_VARARGS, match_start_doc},
{"end", (PyCFunction) match_end, METH_VARARGS, match_end_doc}, {"end", (PyCFunction) match_end, METH_VARARGS, match_end_doc},
{"span", (PyCFunction) match_span, METH_VARARGS, match_span_doc}, {"span", (PyCFunction) match_span, METH_O | METH_D1, match_span_doc},
{"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS, {"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS,
match_groups_doc}, match_groups_doc},
{"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS, {"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS,
......
...@@ -3559,7 +3559,20 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa ...@@ -3559,7 +3559,20 @@ void rearrangeArgumentsInternal(ParamReceiveSpec paramspec, const ParamNames* pa
} }
} }
Box* ovarargs = BoxedTuple::create(unused_positional.size(), unused_positional.data()); Box* ovarargs;
if (argspec.num_args == 0 && paramspec.num_args == 0 && (!varargs || varargs->cls == tuple_cls)) {
// We probably could have cut out a lot more of the overhead in this case:
assert(varargs_size == unused_positional.size());
if (!varargs)
ovarargs = EmptyTuple;
else
ovarargs = varargs;
} else {
ovarargs = BoxedTuple::create(unused_positional.size(), unused_positional.data());
}
assert(ovarargs->cls == tuple_cls);
getArg(varargs_idx, oarg1, oarg2, oarg3, oargs) = ovarargs; getArg(varargs_idx, oarg1, oarg2, oarg3, oargs) = ovarargs;
} else if (unused_positional.size()) { } else if (unused_positional.size()) {
raiseExcHelper(TypeError, "%s() takes at most %d argument%s (%ld given)", func_name_cb(), paramspec.num_args, raiseExcHelper(TypeError, "%s() takes at most %d argument%s (%ld given)", func_name_cb(), paramspec.num_args,
......
...@@ -1867,7 +1867,8 @@ Box* strReplace(Box* _self, Box* _old, Box* _new, Box** _args) { ...@@ -1867,7 +1867,8 @@ Box* strReplace(Box* _self, Box* _old, Box* _new, Box** _args) {
std::string s = self->s(); std::string s = self->s();
bool single_char = old->size() == 1; bool single_char = old->size() == 1;
for (int num_replaced = 0; num_replaced < max_replaces || max_replaces < 0; ++num_replaced) { int num_replaced = 0;
for (; num_replaced < max_replaces || max_replaces < 0; ++num_replaced) {
if (single_char) if (single_char)
start_pos = s.find(old->s()[0], start_pos); start_pos = s.find(old->s()[0], start_pos);
else else
...@@ -1878,6 +1879,10 @@ Box* strReplace(Box* _self, Box* _old, Box* _new, Box** _args) { ...@@ -1878,6 +1879,10 @@ Box* strReplace(Box* _self, Box* _old, Box* _new, Box** _args) {
s.replace(start_pos, old->size(), new_->s()); s.replace(start_pos, old->size(), new_->s());
start_pos += new_->size(); // Handles case where 'to' is a substring of 'from' start_pos += new_->size(); // Handles case where 'to' is a substring of 'from'
} }
if (num_replaced == 0 && self->cls == str_cls)
return self;
return boxString(s); return boxString(s);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment