From: Matthew M. <mma...@us...> - 2004-11-25 18:37:41
|
Update of /cvsroot/nant/nant/src/NAnt.Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30054 Modified Files: DirectoryScanner.cs Log Message: Optimize regexes Index: DirectoryScanner.cs =================================================================== RCS file: /cvsroot/nant/nant/src/NAnt.Core/DirectoryScanner.cs,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** DirectoryScanner.cs 25 Nov 2004 14:42:44 -0000 1.46 --- DirectoryScanner.cs 25 Nov 2004 18:37:31 -0000 1.47 *************** *** 628,635 **** // Check to see if the empty string matches the pattern ! if (path.Length == entry.BaseDirectory.Length) return r.IsMatch(String.Empty); ! if (StringUtils.EndsWith(entry.BaseDirectory, Path.DirectorySeparatorChar)) { return r.IsMatch(path.Substring(entry.BaseDirectory.Length)); } else { --- 628,643 ---- // Check to see if the empty string matches the pattern ! if (path.Length == entry.BaseDirectory.Length) { ! #if DEBUG_REGEXES ! Console.WriteLine("{0} (empty string) [basedir={1}]", entry.Pattern, entry.BaseDirectory); ! #endif return r.IsMatch(String.Empty); + } ! bool endsWithSlash = StringUtils.EndsWith(entry.BaseDirectory, Path.DirectorySeparatorChar); ! #if DEBUG_REGEXES ! Console.WriteLine("{0} ({1}) [basedir={2}]", entry.Pattern, path.Substring(entry.BaseDirectory.Length + ((endsWithSlash) ? 0 : 1)), entry.BaseDirectory); ! #endif ! if (endsWithSlash) { return r.IsMatch(path.Substring(entry.BaseDirectory.Length)); } else { *************** *** 671,675 **** foreach (RegexEntry entry in includedPatterns) { #if DEBUG_REGEXES ! Console.WriteLine("Test include pattern: {0} ({1})", entry.Pattern, path.Substring(entry.BaseDirectory.Length)); #endif if (TestRegex(path, entry, caseSensitive)) --- 679,683 ---- foreach (RegexEntry entry in includedPatterns) { #if DEBUG_REGEXES ! Console.Write("Test include pattern: "); #endif if (TestRegex(path, entry, caseSensitive)) *************** *** 705,709 **** foreach (RegexEntry entry in excludedPatterns) { #if DEBUG_REGEXES ! Console.WriteLine("Test exclude pattern: {0} ({1})", entry.Pattern, path.Substring(entry.BaseDirectory.Length)); #endif if (TestRegex(path, entry, caseSensitive)) --- 713,717 ---- foreach (RegexEntry entry in excludedPatterns) { #if DEBUG_REGEXES ! Console.Write("Test exclude pattern: "); #endif if (TestRegex(path, entry, caseSensitive)) *************** *** 793,806 **** // to match all the files ending in .cs in the src directory OR // subdirectories of src. ! pattern.Replace("**" + seperator, "(?:.+" + seperator + ")|"); ! ! // SPECIAL CASE: to have a pattern like 'bin/**' match subdirectories ! // or files, and the directory itself ! pattern.Replace(seperator + "**", "(?:" + seperator + ".+)|"); ! // | is a place holder for * to prevent it from being replaced in next line pattern.Replace("**", ".|"); pattern.Replace("*", "[^" + seperator + "]*"); ! pattern.Replace('|', '*'); // replace place holder string // Help speed up the search --- 801,811 ---- // to match all the files ending in .cs in the src directory OR // subdirectories of src. ! pattern.Replace(seperator + "**" + seperator, seperator + "(.|?" + seperator + ")?" ); ! pattern.Replace("**" + seperator, ".|(?<=^|" + seperator + ")" ); ! // .| is a place holder for .* to prevent it from being replaced in next line pattern.Replace("**", ".|"); pattern.Replace("*", "[^" + seperator + "]*"); ! pattern.Replace(".|", ".*"); // replace place holder string // Help speed up the search |