SVN: vfmg/trunk/vfmg

sparky sparky at pld-linux.org
Mon Dec 4 01:22:30 CET 2006


Author: sparky
Date: Mon Dec  4 01:22:29 2006
New Revision: 8052

Modified:
   vfmg/trunk/vfmg
Log:
- don't use File::Find, it's way too sophisticated,
  simple replacement gives at least 5% speedup


Modified: vfmg/trunk/vfmg
==============================================================================
--- vfmg/trunk/vfmg	(original)
+++ vfmg/trunk/vfmg	Mon Dec  4 01:22:29 2006
@@ -2,7 +2,6 @@
 # $Id$
 
 use strict;
-use File::Find qw(find);
 use Getopt::Long qw(GetOptions :config bundling);
 use Encode qw(encode decode);
 
@@ -304,14 +303,30 @@
 my @decode_tags = qw(Name);
 eval { push @decode_tags, VFMG::Output::decode_tags() };
 
-find(\&wanted, grep -d, map {"$_/applications"} @xdg_data_dirs);
+sub wanted($);
+sub find_desktop($);
+sub find_desktop($) {
+	my $dir = shift;
+	opendir DIR, $dir or warn "$dir: $!\n" and return;
+	my @fd = map {"$dir/$_"} grep !/^\./, readdir DIR;
+	closedir DIR;
+	foreach my $file (@fd) {
+		if ($file =~ /\.desktop$/) {
+			wanted($file);
+		} elsif (-d $file) {
+			find_desktop($file);
+		}
+	}
+}
+foreach my $dir (grep -d, map {"$_/applications"} @xdg_data_dirs) {
+	find_desktop($dir);
+}
 
-sub wanted { # {{{
-	return unless -f && /^[^.].*\.desktop$/;
-	my $file = $_;
+sub wanted($) { # {{{
+	my $desktop_file = shift;
 
-	open F_IN, $file or warn "$File::Find::name: $!\n" and return;
-	/(.*)\.desktop$/;
+	open F_IN, $desktop_file or warn "$desktop_file: $!\n" and return;
+	$desktop_file =~ m#.*/(.*?)\.desktop$#;
 	my %tags = (
 		file		=> $1,
 		Icon		=> '',
@@ -387,13 +402,13 @@
 		my $enc = $tags{Encoding};
 	
 		if ($enc eq 'Legacy-Mixed') {
-			warn "$File::Find::name: Legacy-Mixed encoding is depreciated.\n";
+			warn "$desktop_file: Legacy-Mixed encoding is depreciated.\n";
 
 			# this code is untested
 			#    --radek
 			my ($lang) = ($first =~ /^$tag_name\[([^\]]+)/);
 			if ($lang !~ /_/) {
-				warn "$File::Find::name: cannot get encoding name for"
+				warn "$desktop_file: cannot get encoding name for"
 				  . " `$lang'. Assuming iso-8859-1\n";
 				$enc = "iso-8859-1";
 			} else {
@@ -410,25 +425,25 @@
 		}
 		$tags{$tag_name} = decode($enc, $tags{$first});
 		unless ($tags{$tag_name}) {
-			warn "$File::Find::name: $first: wrong encoding!\n";
+			warn "$desktop_file: $first: wrong encoding!\n";
 			$tags{$tag_name} = $tags{$first};
 		}
 	}
 	unless ($tags{Name}) {
 		$tags{Name} = $tags{file};
-		warn "$File::Find::name: missing Name tag! using $tags{Name}\n";
+		warn "$desktop_file: missing Name tag! using $tags{Name}\n";
 	}
 	
 	if ( $tags{Exec} =~ /%\S/ ) {
 		$tags{Exec} =~ s/([^%])%v/$1/g;
-		$tags{Exec} =~ s/([^%])%k/$1$file/g;
+		$tags{Exec} =~ s/([^%])%k/$1$desktop_file/g;
 		$tags{Exec} =~ s/([^%])%c/$1$tags{Name}/g;
 		my $iicon = '';
 		$iicon = "--icon $tags{Icon}" if $tags{Icon};
 		$tags{Exec} =~ s/([^%])%i/$1$iicon/g;
 		$tags{Exec} =~ s/%(?i:[fudn])//g;
 		warn "Unknown Exec parameter variable: $1 "
-			."in $File::Find::name, removing\n"
+			."in $desktop_file, removing\n"
 		  if ($tags{Exec} =~ s/(%[^%\s])// and $o_verbose);
 		$tags{Exec} =~ s/%%/%/g;
 	}


More information about the pld-cvs-commit mailing list