[Pcsclite-git-commit] [website] 06/09: matrix: improve the HTML escape code
Ludovic Rousseau
rousseau at moszumanska.debian.org
Wed Oct 28 12:52:05 UTC 2015
This is an automated email from the git hooks/post-receive script.
rousseau pushed a commit to branch master
in repository website.
commit 4889abb7d974589864dc20ea7aece32999967ace
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date: Wed Oct 28 13:31:04 2015 +0100
matrix: improve the HTML escape code
The new code is 5 times faster according to:
$ python -m cProfile -s time matrix.py
Old code:
ncalls tottime percall cumtime percall filename:lineno(function)
326430 1.774 0.000 2.532 0.000 matrix.py:61(html_escape)
12090 0.786 0.000 6.343 0.001 matrix.py:421(add_line)
New code:
ncalls tottime percall cumtime percall filename:lineno(function)
12090 0.623 0.000 4.126 0.000 matrix.py:421(add_line)
326430 0.329 0.000 0.629 0.000 matrix.py:43(html_escape)
The gain is 1.225 seconds.
---
matrix.py | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/matrix.py b/matrix.py
index 77573f8..127722d 100755
--- a/matrix.py
+++ b/matrix.py
@@ -41,18 +41,7 @@ CCID_CLASS_EXCHANGE_MASK = 0x00070000
def html_escape(text):
- """Produce entities within text."""
- html_escape_table = {
- "&": "&",
- '"': """,
- ">": ">",
- "<": "<",
- }
-
- result = list()
- for char in text:
- result.append(html_escape_table.get(char, char))
- return "".join(result)
+ return text.replace("&", "&").replace('"', """).replace(">", ">").replace("<", "<")
def parse_interface(lines):
@@ -431,7 +420,7 @@ def add_line(file_desc, num, reader, fields):
resolution = "width:%dpx;height:%dpx" % (x, y)
file_desc.write('<td><img src="%s" style="%s" alt="image"></td>' % (image, resolution))
- elif field == 'features':
+ elif field in ['features', 'limitations']:
file_desc.write("<td>%s</td>" % ", ".join(reader[field]))
else:
file_desc.write("<td>%s</td>" % html_escape(reader.get(field, "")))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/website.git
More information about the Pcsclite-cvs-commit
mailing list