Skip to content

Commit

Permalink
PERF: slicer.util.importClassesFromDirectory: Compile regex outside f…
Browse files Browse the repository at this point in the history
…or loop

While no significant improvements could be measured, compiling the regex
only once is a sensible choice.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@25113 3bd1e089-480b-0410-8dfb-8563597acbee
  • Loading branch information
jcfr committed May 23, 2016
1 parent 4095862 commit b978865
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Base/Python/slicer/util.py
Expand Up @@ -61,8 +61,9 @@ def importQtClassesFromDirectory(directory, dest_module_name, filematch = '*'):

def importClassesFromDirectory(directory, dest_module_name, type_name, filematch = '*'):
import glob, os, re, fnmatch
re_filematch = re.compile(fnmatch.translate(filematch))
for fname in glob.glob(os.path.join(directory, filematch)):
if not re.compile(fnmatch.translate(filematch)).match(os.path.basename(fname)):
if not re_filematch.match(os.path.basename(fname)):
continue
try:
from_module_name = os.path.splitext(os.path.basename(fname))[0]
Expand Down

0 comments on commit b978865

Please sign in to comment.