Changeset 24 in mp3-find for trunk/lib/MP3
- Timestamp:
- 04/09/06 19:36:20 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/MP3/Find/Filesystem.pm
r14 r24 9 9 use MP3::Info; 10 10 use Scalar::Util qw(looks_like_number); 11 12 eval { 13 require Sort::Key; 14 Sort::Key->import(qw(multikeysorter)); 15 use Sort::Key::Natural; 16 }; 17 my $USE_SORT_KEY = $@ ? 0 : 1; 11 18 12 19 use_winamp_genres(); … … 46 53 # sort the results 47 54 if (@$sort) { 48 @results = sort { 49 my $compare; 50 foreach (map { uc } @$sort) { 51 # use Scalar::Util to do the right sort of comparison 52 $compare = (looks_like_number($a->{$_}) && looks_like_number($b->{$_})) ? 53 $a->{$_} <=> $b->{$_} : 54 $a->{$_} cmp $b->{$_}; 55 # we found a field they differ on 56 last if $compare; 57 } 58 return $compare; 59 } @results; 55 if ($USE_SORT_KEY) { 56 # use Sort::Key to do a (hopefully!) faster sort 57 #TODO: profile this; at first glance, it doesn't actually seem to be any faster 58 #warn "Using Sort::Key"; 59 my $sorter = multikeysorter( 60 sub { my $info = $_; map { $info->{uc $_} } @$sort }, 61 map { 'natural' } @$sort 62 ); 63 @results = $sorter->(@results); 64 } else { 65 @results = sort { 66 my $compare; 67 foreach (map { uc } @$sort) { 68 # use Scalar::Util to do the right sort of comparison 69 $compare = (looks_like_number($a->{$_}) && looks_like_number($b->{$_})) ? 70 $a->{$_} <=> $b->{$_} : 71 $a->{$_} cmp $b->{$_}; 72 # we found a field they differ on 73 last if $compare; 74 } 75 return $compare; 76 } @results; 77 } 60 78 } 61 79
Note: See TracChangeset
for help on using the changeset viewer.