-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
In create_builtin, the loop for searching a match in the inittab array is needlessly exhaustive:
Lines 2357 to 2367 in 9d34623
| struct _inittab *found = NULL; | |
| for (struct _inittab *p = INITTAB; p->name != NULL; p++) { | |
| if (_PyUnicode_EqualToASCIIString(info.name, p->name)) { | |
| found = p; | |
| } | |
| } | |
| if (found == NULL) { | |
| // not found | |
| mod = Py_NewRef(Py_None); | |
| goto finally; | |
| } |
Specifically, once a match is found, there's no point to continue looping the entire array.
This is fairly minor and unnoticeable with a small number of inittab extensions, but can become noticeable with thousands of inittab extensions, and it's also a trivial optimization (just add break, PR incoming), so why not.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usagetype-featureA feature request or enhancementA feature request or enhancement