2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-27 07:02:15 +00:00

- Performance improvements (better psyco support, cache in CppParser)

[SVN r18123]
This commit is contained in:
Bruno da Silva de Oliveira
2003-03-28 12:47:15 +00:00
parent 734657244b
commit bf696026bd
2 changed files with 30 additions and 14 deletions

View File

@@ -19,6 +19,8 @@ class CppParser:
defines = []
self.includes = includes
self.defines = defines
self._cache = []
self._CACHE_SIZE = 5
def _includeparams(self, filename):
@@ -36,6 +38,19 @@ class CppParser:
return ' '.join(defines)
def UpdateCache(self, include, tail, declarations, header):
self._cache.append((include, tail, declarations, header))
if len(self._cache) > self._CACHE_SIZE:
self._cache.pop(0)
def Cache(self, include, tail):
for cache_include, cache_tail, declarations, header in self._cache:
if cache_include == include and cache_tail == tail:
return declarations, header
return None
def FindFileName(self, include):
if os.path.isfile(include):
return include
@@ -47,13 +62,17 @@ class CppParser:
raise RuntimeError, 'Header file "%s" not found!' % name
def parse(self, include, symbols=None, tail=None):
def parse(self, include, tail=None):
'''Parses the given filename, and returns (declaration, header). The
header returned is normally the same as the given to this method,
except if tail is not None: in this case, the header is copied to a temp
filename and the tail code is appended to it before being passed on to gcc.
This temp filename is then returned.
'''
# check if this header was already parsed
cached = self.Cache(include, tail)
if cached:
return cached
filename = self.FindFileName(include)
# copy file to temp folder, if needed
if tail:
@@ -73,14 +92,14 @@ class CppParser:
# call gccxml
cmd = 'gccxml %s %s %s -fxml=%s' \
% (includes, defines, infilename, xmlfile)
if symbols:
cmd += ' -fxml-start=' + ','.join(symbols)
status = os.system(cmd)
if status != 0 or not os.path.isfile(xmlfile):
raise CppParserError, 'Error executing gccxml'
# parse the resulting xml
declarations = ParseDeclarations(xmlfile)
# return the declarations
# cache the results
self.UpdateCache(include, tail, declarations, infilename)
# return the declarations
return declarations, infilename
finally:
if settings.DEBUG and os.path.isfile(xmlfile):

View File

@@ -25,8 +25,9 @@ import exporterutils
import settings
from policies import *
from CppParser import CppParser, CppParserError
import time
__VERSION__ = '0.6.2'
__VERSION__ = '0.6.3'
def GetDefaultIncludes():
if 'INCLUDE' in os.environ:
@@ -150,20 +151,16 @@ def Main():
def UsePsyco():
'Tries to use psyco if it is installed'
'Tries to use psyco if possible'
try:
import psyco
import elementtree.XMLTreeBuilder as XMLTreeBuilder
import GCCXMLParser
psyco.bind(XMLTreeBuilder.fixtext)
psyco.bind(XMLTreeBuilder.fixname)
psyco.bind(XMLTreeBuilder.TreeBuilder)
psyco.bind(GCCXMLParser.GCCXMLParser)
except ImportError: pass
psyco.profile()
except: pass
if __name__ == '__main__':
start = time.clock()
UsePsyco()
status = Main()
print '%0.2f seconds' % (time.clock()-start)
sys.exit(status)