Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Refactor _ignore #20

Merged
merged 1 commit into from

2 participants

dendright Chris McDonough
dendright

When scanning large packages, with a large ignore list, I found a performance improvement in reducing the number of calls to isinstance and str.startswith.

I also think the _ignore function reads better now.

dendright

Any feedback on this? I'd like to get this into the official package rather than maintain my own hacked version.

Chris McDonough
Owner

Sorry, I haven't had time to review this yet. I'm due for a runthrough of Pyramid-related stuff soon; I'm sorry that's the best ETA I can provide.

Chris McDonough mcdonc merged commit be79772 into from
Chris McDonough
Owner

Finally merged, sorry for the lengthy wait. I changed it slightly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 9, 2013
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 15 deletions.
  1. +20 −15 venusian/__init__.py
35 venusian/__init__.py
View
@@ -105,25 +105,30 @@ def onerror(name):
if ignore is not None and not is_nonstr_iter(ignore):
ignore = [ignore]
+ elif ignore is None:
+ ignore = []
+
+ # non-leading-dotted name absolute object name
+ string_ignores = [ign for ign in ignore if isinstance(ign, str)]
+ # leading dotted name relative to scanned package
+ relative_ignores = [ign for ign in string_ignores if ign.startswith('.')]
+ # functions, e.g. re.compile('pattern').search
+ callable_ignores = [ign for ign in ignore if callable(ign)]
def _ignore(fullname):
- if ignore is not None:
- for ign in ignore:
- if isinstance(ign, str):
- if ign.startswith('.'):
- # leading dotted name relative to scanned package
- if fullname.startswith(pkg_name + ign):
- return True
- else:
- # non-leading-dotted name absolute object name
- if fullname.startswith(ign):
- return True
- else:
- # function
- if ign(fullname):
- return True
+ for ign in relative_ignores:
+ if fullname.startswith(pkg_name + ign):
+ return True
+ for ign in string_ignores:
+ # non-leading-dotted name absolute object name
+ if fullname.startswith(ign):
+ return True
+ for ign in callable_ignores:
+ if ign(fullname):
+ return True
return False
+
def invoke(mod_name, name, ob):
fullname = mod_name + '.' + name
Something went wrong with that request. Please try again.