beagle r4570 - trunk/beagle/Filters



Author: dbera
Date: Sat Mar  1 02:25:00 2008
New Revision: 4570
URL: http://svn.gnome.org/viewvc/beagle?rev=4570&view=rev

Log:
Use Compiled Regex whereever possible. And fix some streamreader leaks in the Ebuild filter.


Modified:
   trunk/beagle/Filters/FilterEbuild.cs
   trunk/beagle/Filters/FilterXslt.cs

Modified: trunk/beagle/Filters/FilterEbuild.cs
==============================================================================
--- trunk/beagle/Filters/FilterEbuild.cs	(original)
+++ trunk/beagle/Filters/FilterEbuild.cs	Sat Mar  1 02:25:00 2008
@@ -32,9 +32,9 @@
 namespace Beagle.Filters {
 
 	public class FilterEbuild : FilterPackage {
-		static Regex metadata_pattern = new Regex ("\\s*(?<key>([A-Z_]+))\\s*=\\s*\"(?<value>(.*))\"\\s*");
-		static Regex einfo_pattern = new Regex ("\\s*(einfo|ewarn)\\s+\"(?<message>(.*))\"\\s*");
-		static Regex package_pattern = new Regex ("(?<name>([^0-9]+))-(?<version>(.+)).ebuild");
+		static Regex metadata_pattern = new Regex ("\\s*(?<key>([A-Z_]+))\\s*=\\s*\"(?<value>(.*))\"\\s*", RegexOptions.Compiled);
+		static Regex einfo_pattern = new Regex ("\\s*(einfo|ewarn)\\s+\"(?<message>(.*))\"\\s*", RegexOptions.Compiled);
+		static Regex package_pattern = new Regex ("(?<name>([^0-9]+))-(?<version>(.+)).ebuild", RegexOptions.Compiled);
 
 		public FilterEbuild () 
 		{
@@ -113,21 +113,24 @@
 				if (desktop_file == null)
 					continue;
 				// verify this is a desktop file
-				StreamReader desktop_reader = new StreamReader (new FileStream (desktop_file.FullName, FileMode.Open, FileAccess.Read, FileShare.Read));
-				string desktop_line = null;
-				bool desktop_valid = false;
-				while ((desktop_line = desktop_reader.ReadLine ()) != null) {
-					if (desktop_line.Trim ().Length > 0) {
-						desktop_valid = desktop_line.Equals ("[Desktop Entry]");
-						break;
+				using (StreamReader desktop_reader = new StreamReader (new FileStream (desktop_file.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))) {
+					string desktop_line = null;
+					bool desktop_valid = false;
+					while ((desktop_line = desktop_reader.ReadLine ()) != null) {
+						if (desktop_line.Trim ().Length > 0) {
+							desktop_valid = desktop_line.Equals ("[Desktop Entry]");
+							break;
+						}
 					}
-				}
 				
-				// add property
-				if (desktop_valid)
-					AddProperty (Beagle.Property.NewUnsearched ("fixme:desktop_file", desktop_file.FullName));
+					// add property
+					if (desktop_valid)
+						AddProperty (Beagle.Property.NewUnsearched ("fixme:desktop_file", desktop_file.FullName));
+				}
 			}
 
+			contents_reader.Close ();
+
 			AddProperty (Beagle.Property.NewUnsearched ("fixme:contents_byte_count", byte_count));
 			AddProperty (Beagle.Property.NewUnsearched ("fixme:contents_file_count", file_count));
 			AddProperty (Beagle.Property.NewUnsearched ("fixme:contents_dir_count", dir_count));

Modified: trunk/beagle/Filters/FilterXslt.cs
==============================================================================
--- trunk/beagle/Filters/FilterXslt.cs	(original)
+++ trunk/beagle/Filters/FilterXslt.cs	Sat Mar  1 02:25:00 2008
@@ -37,8 +37,8 @@
 {
 	public class FilterXslt : Filter 
 	{
-		Regex xpath_variables_regex = new Regex ("\\$(?<name>[\\wS][\\wS\\d-:]*)");
-		Regex xpath_functions_regex = new Regex ("(?<name>[\\wS][\\wS\\d-:]*)\\(");
+		static Regex xpath_variables_regex = new Regex ("\\$(?<name>[\\wS][\\wS\\d-:]*)", RegexOptions.Compiled);
+		static Regex xpath_functions_regex = new Regex ("(?<name>[\\wS][\\wS\\d-:]*)\\(", RegexOptions.Compiled);
 
 		public FilterXslt ()
 		{



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