[Patch]



Hey,

Here's a patch to make the importing a bit less expensive. In many cases
the callers of ImageFile.HasLoader() already have FileInfo instances, no
need to jump through hoops (and create a bunch of extra objects per
file) to get their extensions. It also removes a debug
Console.WriteLine() which shaves off 1/3 of the ImportBackend.Prepare()
total time.

Tambet
Index: DirectoryCollection.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/DirectoryCollection.cs,v
retrieving revision 1.25
diff -u -r1.25 DirectoryCollection.cs
--- DirectoryCollection.cs	24 Mar 2006 22:43:23 -0000	1.25
+++ DirectoryCollection.cs	26 Aug 2006 17:47:41 -0000
@@ -163,7 +163,7 @@
 		{
 			ArrayList items = new ArrayList ();
 			foreach (FileInfo f in files) {
-				if (FSpot.ImageFile.HasLoader (f.FullName)) {
+				if (FSpot.ImageFile.HasLoader (f)) {
 					Console.WriteLine (f.FullName);
 					items.Add (new FileBrowsableItem (f.FullName));
 				}
Index: FileImportBackend.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/FileImportBackend.cs,v
retrieving revision 1.36
diff -u -r1.36 FileImportBackend.cs
--- FileImportBackend.cs	18 Jul 2006 23:17:42 -0000	1.36
+++ FileImportBackend.cs	26 Aug 2006 17:47:41 -0000
@@ -39,17 +39,16 @@
 		
 		public ImportInfo (string original)
 		{
-			original_path
- = original;
-		        destination_path= null;
+			original_path = original;
+			destination_path= null;
 			Photo = null;
 		}
 	}
 	
-	private void AddPath (string path)
+	private void AddPath (System.IO.FileInfo file)
 	{
-		if (FSpot.ImageFile.HasLoader (path))
-			import_info.Add (new ImportInfo (path));
+		if (FSpot.ImageFile.HasLoader (file))
+			import_info.Add (new ImportInfo (file.FullName));
 	}
 
 	private void GetListing (System.IO.DirectoryInfo info)
@@ -65,7 +64,7 @@
 
 	private void GetListing (System.IO.DirectoryInfo dirinfo, System.IO.FileInfo [] files, bool recurse)
 	{
-		System.Console.WriteLine ("Scanning {0}", dirinfo.FullName);
+		//System.Console.WriteLine ("Scanning {0}", dirinfo.FullName);
 		Hashtable exiting_entries = new Hashtable ();
 
 		foreach (Photo p in store.Query (dirinfo)) {
@@ -82,7 +81,7 @@
 	
 		foreach (System.IO.FileInfo f in files) {
 			if (! exiting_entries.Contains (f.Name)) {
-				AddPath (f.FullName);
+				AddPath (f);
 			}
 		}
 
Index: ImageFile.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/ImageFile.cs,v
retrieving revision 1.32
diff -u -r1.32 ImageFile.cs
--- ImageFile.cs	22 Mar 2006 21:24:02 -0000	1.32
+++ ImageFile.cs	26 Aug 2006 17:47:41 -0000
@@ -1,4 +1,5 @@
 using System;
+using System.Collections;
 using System.IO;
 
 namespace FSpot {
@@ -11,7 +12,7 @@
 	public class ImageFile {
 		protected Uri uri;
 
-		static System.Collections.Hashtable name_table;
+		static Hashtable name_table;
 
 		public ImageFile (string path) 
 		{
@@ -31,7 +32,7 @@
 			//if (vfs.IsLocal)
 			//	return File.OpenRead (uri.LocalPath);
 
-			System.Console.WriteLine ("open uri = {0}", uri.ToString ());
+			//System.Console.WriteLine ("open uri = {0}", uri.ToString ());
 			return new Gnome.Vfs.VfsStream (uri.ToString (), FileMode.Open);
 		}
 
@@ -42,7 +43,9 @@
 
 		static ImageFile ()
 		{
-			name_table = new System.Collections.Hashtable ();
+			name_table = new Hashtable (new CaseInsensitiveHashCodeProvider (),
+										new CaseInsensitiveComparer ());
+
 			name_table [".svg"] = typeof (FSpot.Svg.SvgFile);
 			name_table [".gif"] = typeof (ImageFile);
 			name_table [".jpeg"] = typeof (JpegFile);
@@ -147,18 +150,15 @@
 			}
 		}
 
-		public static bool HasLoader (string path)
-		{
-			return HasLoader (UriList.PathToFileUri (path));
-		}
-		
 		public static bool HasLoader (Uri uri)
 		{
 			string path = uri.AbsolutePath;
-			string extension = System.IO.Path.GetExtension (path).ToLower ();
-			System.Type t = (System.Type) name_table [extension];
-			
-			return (t != null);
+			return name_table.ContainsKey (System.IO.Path.GetExtension (path));
+		}
+
+		public static bool HasLoader (System.IO.FileInfo file)
+		{
+			return name_table.ContainsKey (file.Extension);
 		}
 
 		public static ImageFile Create (string path)
@@ -169,7 +169,7 @@
 		public static ImageFile Create (Uri uri)
 		{
 			string path = uri.AbsolutePath;
-			string extension = System.IO.Path.GetExtension (path).ToLower ();
+			string extension = System.IO.Path.GetExtension (path);
 			System.Type t = (System.Type) name_table [extension];
 			ImageFile img;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]