summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDieter Verfaillie <dieterv@optionexplicit.be>2013-04-24 17:41:49 +0200
committerDieter Verfaillie <dieterv@optionexplicit.be>2013-05-07 15:36:09 +0200
commitb70fe6a5649ed037f2554ae13067fd9929d841f8 (patch)
treeaf8559063bef610538eef48c01c8ae71c2b61bd3
parentbeadfeff33302a3012fb5df1a7197cb4fac8f6f6 (diff)
downloadgobject-introspection-b70fe6a5649ed037f2554ae13067fd9929d841f8.tar.gz
giscanner: Define source and header filename extensions only once
Enables us to to use a more effecient list membership test instead of testing the end of some string multiple times. https://bugzilla.gnome.org/show_bug.cgi?id=699533
-rwxr-xr-xgiscanner/scannermain.py7
-rw-r--r--giscanner/sourcescanner.py7
2 files changed, 7 insertions, 7 deletions
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index b068f6fb..deefcf99 100755
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -38,7 +38,7 @@ from giscanner.girparser import GIRParser
from giscanner.girwriter import GIRWriter
from giscanner.maintransformer import MainTransformer
from giscanner.shlibs import resolve_shlibs
-from giscanner.sourcescanner import SourceScanner
+from giscanner.sourcescanner import SourceScanner, ALL_EXTS
from giscanner.transformer import Transformer
from . import utils
@@ -253,10 +253,7 @@ def extract_filenames(args):
for arg in args:
# We don't support real C++ parsing yet, but we should be able
# to understand C API implemented in C++ files.
- if (arg.endswith('.c') or arg.endswith('.cpp') or
- arg.endswith('.cc') or arg.endswith('.cxx') or
- arg.endswith('.h') or arg.endswith('.hpp') or
- arg.endswith('.hxx')):
+ if os.path.splitext(arg)[1] in ALL_EXTS:
if not os.path.exists(arg):
_error('%s: no such a file or directory' % (arg, ))
# Make absolute, because we do comparisons inside scannerparser.c
diff --git a/giscanner/sourcescanner.py b/giscanner/sourcescanner.py
index bd84a605..a1103a10 100644
--- a/giscanner/sourcescanner.py
+++ b/giscanner/sourcescanner.py
@@ -32,6 +32,10 @@ with LibtoolImporter(None, None):
else:
from giscanner._giscanner import SourceScanner as CSourceScanner
+HEADER_EXTS = ['.h', '.hpp', '.hxx']
+SOURCE_EXTS = ['.c', '.cpp', '.cc', '.cxx']
+ALL_EXTS = SOURCE_EXTS + HEADER_EXTS
+
(CSYMBOL_TYPE_INVALID,
CSYMBOL_TYPE_ELLIPSIS,
CSYMBOL_TYPE_CONST,
@@ -241,8 +245,7 @@ class SourceScanner(object):
headers = []
for filename in filenames:
- if (filename.endswith('.c') or filename.endswith('.cpp') or
- filename.endswith('.cc') or filename.endswith('.cxx')):
+ if os.path.splitext(filename)[1] in SOURCE_EXTS:
filename = os.path.abspath(filename)
self._scanner.lex_filename(filename)
else: