Commit be7aae75 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Microoptimizations

parent 76c42191
...@@ -298,7 +298,7 @@ Box* BoxedMethodDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, A ...@@ -298,7 +298,7 @@ Box* BoxedMethodDescriptor::tppCall(Box* _self, CallRewriteArgs* rewrite_args, A
Box** oargs = NULL; Box** oargs = NULL;
Box* oargs_array[1]; Box* oargs_array[1];
if (paramspec.totalReceived() >= 3) { if (paramspec.totalReceived() > 3) {
assert((paramspec.totalReceived() - 3) <= sizeof(oargs_array) / sizeof(oargs_array[0])); assert((paramspec.totalReceived() - 3) <= sizeof(oargs_array) / sizeof(oargs_array[0]));
oargs = oargs_array; oargs = oargs_array;
} }
......
...@@ -1018,7 +1018,7 @@ template <ExceptionStyle S> Box* intNew(Box* _cls, Box* val, Box* base) noexcept ...@@ -1018,7 +1018,7 @@ template <ExceptionStyle S> Box* intNew(Box* _cls, Box* val, Box* base) noexcept
return n; return n;
if (S == CAPI) { if (S == CAPI) {
PyErr_Format(OverflowError, "Python int too large to convert to C long"); PyErr_SetString(OverflowError, "Python int too large to convert to C long");
return NULL; return NULL;
} else } else
raiseExcHelper(OverflowError, "Python int too large to convert to C long"); raiseExcHelper(OverflowError, "Python int too large to convert to C long");
......
...@@ -3074,13 +3074,25 @@ void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_name ...@@ -3074,13 +3074,25 @@ void rearrangeArguments(ParamReceiveSpec paramspec, const ParamNames* param_name
for (int i = 3; i < num_passed_args; i++) { for (int i = 3; i < num_passed_args; i++) {
assert(gc::isValidGCObject(args[i - 3]) || args[i - 3] == NULL); assert(gc::isValidGCObject(args[i - 3]) || args[i - 3] == NULL);
} }
assert((oargs != NULL) == (num_output_args > 3));
assert((defaults != NULL) == (paramspec.num_defaults != 0)); assert((defaults != NULL) == (paramspec.num_defaults != 0));
if (rewrite_args) { if (rewrite_args) {
rewrite_success = false; // default case rewrite_success = false; // default case
} }
// Super fast path:
if (argspec.num_keywords == 0 && !argspec.has_starargs && !paramspec.takes_varargs && !argspec.has_kwargs
&& argspec.num_args == paramspec.num_args && !paramspec.takes_kwargs) {
rewrite_success = true;
oarg1 = arg1;
oarg2 = arg2;
oarg3 = arg3;
if (num_output_args > 3)
memcpy(oargs, args, sizeof(Box*) * (num_output_args - 3));
return;
}
// Fast path: if it's a simple-enough call, we don't have to do anything special. On a simple // Fast path: if it's a simple-enough call, we don't have to do anything special. On a simple
// django-admin test this covers something like 93% of all calls to callFunc. // django-admin test this covers something like 93% of all calls to callFunc.
if (argspec.num_keywords == 0 && argspec.has_starargs == paramspec.takes_varargs && !argspec.has_kwargs if (argspec.num_keywords == 0 && argspec.has_starargs == paramspec.takes_varargs && !argspec.has_kwargs
......
...@@ -877,7 +877,8 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo ...@@ -877,7 +877,8 @@ static Box* typeCallInner(CallRewriteArgs* rewrite_args, ArgPassSpec argspec, Bo
} else { } else {
new_attr = typeLookup(cls, new_str, NULL); new_attr = typeLookup(cls, new_str, NULL);
try { try {
new_attr = processDescriptor(new_attr, None, cls); if (new_attr->cls != function_cls) // optimization
new_attr = processDescriptor(new_attr, None, cls);
} catch (ExcInfo e) { } catch (ExcInfo e) {
if (S == CAPI) { if (S == CAPI) {
setCAPIException(e); setCAPIException(e);
......
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