[4suite-checkins] [XPATH_OPTIMIZATIONS-branch] In
4Suite/Ft/Xml/Xslt, files CallTemplateElement.py,
ChooseElement.py, ForEachElement.py, _4xslt.py
Jeremy Kloth
jkloth at 4suite.org
Fri Dec 15 15:11:57 MST 2006
Branch: XPATH_OPTIMIZATIONS-branch
Modified Files:
CallTemplateElement.py ChooseElement.py ForEachElement.py _4xslt.py
Log Message:
Added direct Python bytecode compilation of XPath expressions
ViewCVS diff:
http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/Xslt/CallTemplateElement.py.diff?r1=1.13&r2=1.13.2.1
ViewCVS view:
http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/Xslt/CallTemplateElement.py?rev=1.13.2.1&content-type=text/vnd.viewcvs-markup
Index: CallTemplateElement.py
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/Xslt/CallTemplateElement.py,v
retrieving revision 1.13
retrieving revision 1.13.2.1
diff -U2 -r1.13 -r1.13.2.1
--- CallTemplateElement.py 29 Nov 2006 02:10:08 -0000 1.13
+++ CallTemplateElement.py 15 Dec 2006 22:11:57 -0000 1.13.2.1
@@ -31,5 +31,5 @@
self._tail_recursive = 0
self._called_template = None
- self._params = [ (child, child._name, child._select.evaluate)
+ self._params = [ (child, child._name, child._select)
for child in self.children ]
return
@@ -80,5 +80,5 @@
context.processorNss = param.namespaces
context.currentInstruction = param
- params[name] = expr(context)
+ params[name] = expr.evaluate(context)
if self._tail_recursive:
@@ -95,5 +95,5 @@
def __setstate__(self, state):
XsltElement.__setstate__(self, state)
- self._params = [ (child, child._name, child._select.evaluate)
+ self._params = [ (child, child._name, child._select)
for child in self.children ]
return
ViewCVS diff:
http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/Xslt/ChooseElement.py.diff?r1=1.6.2.1&r2=1.6.2.2
ViewCVS view:
http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/Xslt/ChooseElement.py?rev=1.6.2.2&content-type=text/vnd.viewcvs-markup
Index: ChooseElement.py
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/Xslt/ChooseElement.py,v
retrieving revision 1.6.2.1
retrieving revision 1.6.2.2
diff -U2 -r1.6.2.1 -r1.6.2.2
--- ChooseElement.py 4 Dec 2006 07:56:51 -0000 1.6.2.1
+++ ChooseElement.py 15 Dec 2006 22:11:57 -0000 1.6.2.2
@@ -52,6 +52,5 @@
self._choices = self.children
self._otherwise = None
- self._choices = [ (child, child._test.evaluateAsBoolean)
- for child in self._choices ]
+ self._choices = [ (child, child._test) for child in self._choices ]
return
@@ -61,5 +60,5 @@
context.processorNss = child.namespaces
context.currentInstruction = child
- if test(context):
+ if test.evaluateAsBoolean(context):
chosen = child
break
@@ -81,4 +80,4 @@
XsltElement.__setstate__(self, state)
choices = self.children[:(self._otherwise and -1 or 0)]
- self._choices = [ (child, child._test.evaluate) for child in choices ]
+ self._choices = [ (child, child._test) for child in choices ]
return
ViewCVS diff:
http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/Xslt/ForEachElement.py.diff?r1=1.8.2.1&r2=1.8.2.2
ViewCVS view:
http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/Xslt/ForEachElement.py?rev=1.8.2.2&content-type=text/vnd.viewcvs-markup
Index: ForEachElement.py
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/Xslt/ForEachElement.py,v
retrieving revision 1.8.2.1
retrieving revision 1.8.2.2
diff -U2 -r1.8.2.1 -r1.8.2.2
--- ForEachElement.py 4 Dec 2006 07:56:51 -0000 1.8.2.1
+++ ForEachElement.py 15 Dec 2006 22:11:57 -0000 1.8.2.2
@@ -14,4 +14,5 @@
from Ft.Xml import EMPTY_NAMESPACE
+from Ft.Xml.XPath.cDataTypes import NodeSet
from Ft.Xml.Xslt import XsltElement, XsltRuntimeException, Error, XSL_NAMESPACE
from Ft.Xml.Xslt import CategoryTypes, ContentInfo, AttributeInfo
@@ -32,5 +33,6 @@
def setup(self):
- sort_keys = filter(lambda x: isinstance(x, SortElement), self.children)
+ sort_keys = [ child for child in self.children
+ if isinstance(child, SortElement) ]
if sort_keys:
self._select = SortedExpression(self._select, sort_keys)
@@ -43,9 +45,9 @@
if self._select:
try:
- node_set = self._select.select(context, [context.node])
+ nodes = self._select.evaluateAsNodeSet(context)
except TypeError:
raise XsltRuntimeException(Error.INVALID_FOREACH_SELECT, self)
else:
- node_set = context.node
+ nodes = NodeSet(context.node)
children = [ child.instantiate for child in self.children ]
@@ -53,5 +55,5 @@
pos = 1
size = 0 #len(node_set)
- for node in node_set:
+ for node in nodes:
context.node, context.position, context.size = node, pos, size
context.currentNode = node
ViewCVS diff:
http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/Xslt/_4xslt.py.diff?r1=1.52&r2=1.52.2.1
ViewCVS view:
http://cvs.4suite.org/viewcvs/4Suite/Ft/Xml/Xslt/_4xslt.py?rev=1.52.2.1&content-type=text/vnd.viewcvs-markup
Index: _4xslt.py
===================================================================
RCS file: /var/local/cvsroot/4Suite/Ft/Xml/Xslt/_4xslt.py,v
retrieving revision 1.52
retrieving revision 1.52.2.1
diff -U2 -r1.52 -r1.52.2.1
--- _4xslt.py 29 Nov 2006 02:10:08 -0000 1.52
+++ _4xslt.py 15 Dec 2006 22:11:57 -0000 1.52.2.1
@@ -29,4 +29,10 @@
sys.setrecursionlimit(MAX_PYTHON_RECURSION_DEPTH)
+# On Windows, the best timer is time.clock().
+# On most other platforms the best timer is time.time().
+if sys.platform == "win32":
+ default_timer = time.clock
+else:
+ default_timer = time.time
class XsltCommandLineApp(CommandLineApp.CommandLineApp):
@@ -384,6 +390,10 @@
# -- Prepare for reflexive transform -------------------------------
- if options.has_key('reflex'):
- xinclude = not options.has_key('noxinclude')
+ total_start = default_timer()
+ compile_start = default_timer()
+
+ xinclude = 'noxinclude' not in options
+
+ if 'reflex' in options:
source_arg = args['source-uri']
try:
@@ -409,8 +419,6 @@
else:
- xinclude = not options.has_key('noxinclude')
- instant = options.has_key('instant')
source_arg = args['source-uri']
- if instant:
+ if 'instant' in options:
sty_arg = args['stylesheet-uri'][0]
try:
@@ -453,4 +461,6 @@
ReportFatalException(e, stacktrace_on_error)
+ compile_end = default_timer()
+
# -- Gather transformation-time options ----------------------------
@@ -481,6 +491,5 @@
# misc runtime flags
- ignore_pis = options.has_key('ignore')
- checktime = options.has_key('time')
+ ignore_pis = 'ignore' in options
# -- Do the transformation -----------------------------------------
@@ -491,11 +500,9 @@
raise TypeError('No source document to transform!')
+ transform_start = default_timer()
if sty_chain:
resultstream = StringIO()
- if checktime:
- start = time.time()
- i = 0
+ i = 1
for sty_isrc in sty_chain[:-1]:
- i += 1
# FIXME:
# use RtfWriter to make each result be a Domlette document,
@@ -515,4 +522,5 @@
source_isrc = source_isrc.clone(sourcestream, new_uri)
resultstream = StringIO()
+ i += 1
processor.appendStylesheet(sty_chain[-1])
@@ -520,20 +528,14 @@
topLevelParams=top_level_params,
outputStream=out_file)
- if checktime:
- end = time.time()
-
CloseStream(source_isrc, quiet=True)
else:
- if checktime:
- start = time.time()
processor.run(source_isrc, ignore_pis,
topLevelParams=top_level_params,
outputStream=out_file)
- if checktime:
- end = time.time()
- CloseStream(source_isrc, quiet=True)
+ transform_end = default_timer()
+ CloseStream(source_isrc, quiet=True)
except Exception, e:
ReportFatalException(e, stacktrace_on_error)
@@ -541,4 +543,6 @@
# -- Handle post-transformation tasks ------------------------------
+ total_end = default_timer()
+
try:
if out_file.isatty():
@@ -550,6 +554,25 @@
pass
- if checktime:
- sys.stderr.write("Transformation time: %dms\n" % (1000 * (end - start)))
+ if 'time' in options:
+ def display_time(heading, seconds):
+ milliseconds = seconds * 1000
+ if milliseconds < 1:
+ digits = 4
+ elif milliseconds < 10:
+ digits = 3
+ elif milliseconds < 100:
+ digits = 2
+ elif milliseconds < 1000:
+ digits = 1
+ else:
+ digits = 0
+ print >> sys.stderr, heading, '%0.*fms' % (digits, milliseconds)
+ compile_time = (compile_end - compile_start)
+ transform_time = (transform_end - transform_start)
+ total_time = (total_end - total_start)
+
+ display_time("Stylesheet load/compile time:", compile_time)
+ display_time("Transformation time: ", transform_time)
+ display_time("Total execution time: ", total_time)
return
More information about the 4suite-checkins
mailing list