[Checkins] SVN: z3c.pt/trunk/ Replaced the cgi.escape function by
an optimized local version,
we go up to 11x for path and 16x for Python expressions :) In the
bigtable benchmark the enhancement is more noticable - we are
the same speed as spitfire -O1 templates now and just half
the speed of -O3 :))
Hanno Schlichting
plone at hannosch.info
Thu Jul 17 17:30:01 EDT 2008
Log message for revision 88466:
Replaced the cgi.escape function by an optimized local version, we go up to 11x for path and 16x for Python expressions :) In the bigtable benchmark the enhancement is more noticable - we are the same speed as spitfire -O1 templates now and just half the speed of -O3 :))
Changed:
U z3c.pt/trunk/CHANGES.txt
U z3c.pt/trunk/benchmark/benchmark/bigtable.py
U z3c.pt/trunk/src/z3c/pt/clauses.py
U z3c.pt/trunk/src/z3c/pt/generation.py
-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt 2008-07-17 20:51:51 UTC (rev 88465)
+++ z3c.pt/trunk/CHANGES.txt 2008-07-17 21:29:42 UTC (rev 88466)
@@ -4,6 +4,11 @@
Version 0.8.x
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+- Replaced the cgi.escape function by an optimized local version, we go up
+ to 11x for path and 16x for Python expressions :) In the bigtable benchmark
+ the enhancement is more noticable - we are the same speed as spitfire -O1
+ templates now and just half the speed of -O3 :))
+
- Added a new benchmark test called bigtable that produces results which are
directly comparable to those produced by the bigtable.py benchmark in the
spitfire project.
Modified: z3c.pt/trunk/benchmark/benchmark/bigtable.py
===================================================================
--- z3c.pt/trunk/benchmark/benchmark/bigtable.py 2008-07-17 20:51:51 UTC (rev 88465)
+++ z3c.pt/trunk/benchmark/benchmark/bigtable.py 2008-07-17 21:29:42 UTC (rev 88466)
@@ -51,7 +51,10 @@
tests = ['test_z3c']
for test in tests:
- setup = 'from __main__ import setup, %s; setup(); %s()' % (test, test)
+ if which:
+ setup = 'from __main__ import setup, %s; setup()' % test
+ else:
+ setup = 'from __main__ import setup, %s; setup(); %s()' % (test, test)
t = timeit.Timer(setup=setup,
stmt='%s()' % test)
Modified: z3c.pt/trunk/src/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/clauses.py 2008-07-17 20:51:51 UTC (rev 88465)
+++ z3c.pt/trunk/src/z3c/pt/clauses.py 2008-07-17 21:29:42 UTC (rev 88466)
@@ -504,18 +504,18 @@
if unicode_required_flag:
stream.write("if isinstance(%s, unicode):" % temp)
stream.indent()
- stream.write("_write(' %s=\"'+_escape(%s,True)+'\"')" %
+ stream.write("_write(' %s=\"'+_escape(%s,1)+'\"')" %
(attribute, temp))
stream.outdent()
stream.write("elif %s is not None:" % temp)
stream.indent()
- stream.write("_write(' %s=\"'+_escape(str(%s),True)+'\"')" %
+ stream.write("_write(' %s=\"'+_escape(str(%s),1)+'\"')" %
(attribute, temp))
stream.outdent()
else:
stream.write("if %s is not None:" % temp)
stream.indent()
- stream.write("_write(' %s=\"'+_escape(str(%s),True)+'\"')" %
+ stream.write("_write(' %s=\"'+_escape(str(%s),1)+'\"')" %
(attribute, temp))
stream.outdent()
Modified: z3c.pt/trunk/src/z3c/pt/generation.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/generation.py 2008-07-17 20:51:51 UTC (rev 88465)
+++ z3c.pt/trunk/src/z3c/pt/generation.py 2008-07-17 21:29:42 UTC (rev 88466)
@@ -46,6 +46,18 @@
return target_language
return negotiate(context)
+def _escape(s, quote=0):
+ """Replace special characters '&', '<' and '>' by SGML entities."""
+ if '&' in s:
+ s = s.replace("&", "&") # Must be done first!
+ if '<' in s:
+ s = s.replace("<", "<")
+ if '>' in s:
+ s = s.replace(">", ">")
+ if quote:
+ s = s.replace('"', """)
+ return s
+
def initialize_i18n():
if DISABLE_I18N:
return (None, _fake_negotiate, _fake_translate)
@@ -55,7 +67,7 @@
return ({}, utils.repeatdict())
def initialize_helpers():
- return (cgi.escape, object())
+ return (_escape, object())
def initialize_stream():
out = BufferIO()
More information about the Checkins
mailing list