Subject: | [PATCH] optimize isSpace, isEndSpace and isWhitespace |
The attached patch optimizes isSpace, isEndSpace and isWhitespace
These are hot paths, and for example the way OTRS uses Javascript::Minifier,
isWhitespace is called more than 100k times, taking up more than 700ms.
Subject: | 0001-optimize-isSpace-isEndSpace-and-isWhitespace.patch |
From 381fddbb1aaadc8e3567668a1e4da95d26fba160 Mon Sep 17 00:00:00 2001
From: Moritz Lenz <moritz@faui2k3.org>
Date: Tue, 10 Dec 2013 09:39:51 +0100
Subject: [PATCH] optimize isSpace, isEndSpace and isWhitespace
these are hot paths, and for example the way OTRS uses Javascript::Minier,
isWhitespace is called more than 100k times, taking up more than 700ms.
Introduces no behavioral changes.
---
lib/JavaScript/Minifier.pm | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/lib/JavaScript/Minifier.pm b/lib/JavaScript/Minifier.pm
index ac005e1..31b63bb 100644
--- a/lib/JavaScript/Minifier.pm
+++ b/lib/JavaScript/Minifier.pm
@@ -17,19 +17,20 @@ sub isAlphanum {
return ($x =~ /[\w\$\\]/ || ord($x) > 126);
}
+# a hot path, so optimized
sub isSpace {
- my $x = shift;
- return ($x eq ' ' || $x eq "\t");
+ return ($_[0] eq ' ' || $_[0] eq "\t");
}
+# a hot path, so optimized
sub isEndspace {
- my $x = shift;
- return ($x eq "\n" || $x eq "\r" || $x eq "\f");
+ return ($_[0] eq "\n" || $_[0] eq "\r" || $_[0] eq "\f");
}
+# a hot path, so optimized
sub isWhitespace {
- my $x = shift;
- return (isSpace($x) || isEndspace($x));
+ return ($_[0] eq ' ' || $_[0] eq "\t"
+ || $_[0] eq "\n" || $_[0] eq "\r" || $_[0] eq "\f");
}
# New line characters before or after these characters can be removed.
--
1.7.9.5