Permalink
Browse files

Item14066: fixed performance of getTopicNames

Before:

sort { NFKD($a) cmp NFKD($b) }

After:

map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [ $_, NFKD($_) ] }

... same thing but a lot faster.
  • Loading branch information...
1 parent 14838b8 commit 67c475371bf6d1adc6e18d1d46b7f54226fb3940 MichaelDaum committed May 10, 2016
Showing with 5 additions and 1 deletion.
  1. +5 −1 RCSStoreContrib/lib/Foswiki/Store/Rcs/Handler.pm
@@ -35,6 +35,7 @@ use File::Copy ();
use File::Copy::Recursive ();
use File::Spec ();
use File::Path ();
+use Unicode::Normalize;
use Fcntl qw( :DEFAULT :flock SEEK_SET );
use Encode ();
@@ -583,12 +584,15 @@ sub getTopicNames {
# the name filter is used to ensure we don't return filenames
# that contain illegal characters as topic names.
my @topicList =
+ map { $_->[0] }
+ sort { $a->[1] cmp $b->[1] }
+ map { [ $_, NFKD($_) ] }
map { /^(.*)\.txt$/; $1; }
- sort { NFKD($a) cmp NFKD($b) } # unicode aware
grep { !/$Foswiki::cfg{NameFilter}/ && /\.txt$/ }
# Must _decode before applying the NameFilter and sort
map( _decode($_), readdir($dh) );
+
closedir($dh);
return @topicList;
}

0 comments on commit 67c4753

Please sign in to comment.