[lintian] 01/01: r/html_reports: Optimise away some regex subst
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit 970ebdd27b3cb1034a2bba2d35fec699877983c7
Author: Niels Thykier <niels@thykier.net>
Date: Mon Feb 3 22:14:55 2014 +0100
r/html_reports: Optimise away some regex subst
Use index() to skip some s/// invocations. When profiling
html_reports, this seems to reduce the runtime with about 30s.
For reference, html_quote is called about 5.6 million times, but the
"escapble" characters are only found in 9-10k, ~7k and ~7k of strings
checked (respectively). In other words, no more than 0.5% of the
strings need any escaping (in practise).
Signed-off-by: Niels Thykier <niels@thykier.net>
---
reporting/html_reports | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/reporting/html_reports b/reporting/html_reports
index 23fe3a3..3432434 100755
--- a/reporting/html_reports
+++ b/reporting/html_reports
@@ -747,9 +747,18 @@ sub maintainer_url {
sub html_quote {
my ($text) = @_;
$text ||= '';
- $text =~ s/&/\&/g;
- $text =~ s/</\</g;
- $text =~ s/>/\>/g;
+ # Use index to do a quick check before we bother requesting a
+ # subst. On average, this is cheaper than blindly s///'ing, since
+ # we rarely subst (all) of the characters below.
+ if (index($text, '&') > -1) {
+ $text =~ s/&/\&/g;
+ }
+ if (index($text, '<') > -1) {
+ $text =~ s/</\</g;
+ }
+ if (index($text, '>') > -1) {
+ $text =~ s/>/\>/g;
+ }
return $text;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: