You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by mb...@apache.org on 2005/03/02 23:43:54 UTC
cvs commit: ant/src/main/org/apache/tools/ant DirectoryScanner.java
mbenson 2005/03/02 14:43:54
Modified: src/main/org/apache/tools/ant DirectoryScanner.java
Log:
Stop scanning directories where we match the directory but know based
on the pattern that we will never match any of its contents.
Revision Changes Path
1.91 +19 -5 ant/src/main/org/apache/tools/ant/DirectoryScanner.java
Index: DirectoryScanner.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DirectoryScanner.java,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -r1.90 -r1.91
--- DirectoryScanner.java 11 Feb 2005 22:49:56 -0000 1.90
+++ DirectoryScanner.java 2 Mar 2005 22:43:54 -0000 1.91
@@ -1117,7 +1117,7 @@
dirsDeselected.addElement(name);
}
everythingIncluded &= included;
- if (fast && (included || couldHoldIncluded(name))) {
+ if (fast && couldHoldIncluded(name)) {
scandir(file, name + File.separator, fast);
}
}
@@ -1156,16 +1156,30 @@
*/
protected boolean couldHoldIncluded(String name) {
for (int i = 0; i < includes.length; i++) {
- if (matchPatternStart(includes[i], name, isCaseSensitive())) {
- if (isMorePowerfulThanExcludes(name, includes[i])) {
- return true;
- }
+ if (matchPatternStart(includes[i], name, isCaseSensitive())
+ && isMorePowerfulThanExcludes(name, includes[i])
+ && isDeeper(includes[i], name)) {
+ return true;
}
}
return false;
}
/**
+ * Verify that a pattern specifies files deeper
+ * than the level of the specified file.
+ * @param pattern the pattern to check.
+ * @param name the name to check.
+ * @return whether the pattern is deeper than the name.
+ * @since Ant 1.6.3
+ */
+ private boolean isDeeper(String pattern, String name) {
+ Vector p = SelectorUtils.tokenizePath(pattern);
+ Vector n = SelectorUtils.tokenizePath(name);
+ return p.contains("**") || p.size() > n.size();
+ }
+
+ /**
* Find out whether one particular include pattern is more powerful
* than all the excludes.
* Note: the power comparison is based on the length of the include pattern
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: cvs commit: ant/src/main/org/apache/tools/ant DirectoryScanner.java
Posted by Matt Benson <gu...@yahoo.com>.
--- Antoine Levy-Lambert <an...@gmx.de> wrote:
> Hello Matt and others,
>
> I had thought about this issue of optimizing pattern
> scanning.
> DirectoryScanner used to be written so that if an
> exclude pattern looks like
> foo/bar/** scanning stops in foo/bar.
> Actually if an exclude pattern is like **/Test/**,
> every time a directory Test is encountered it should
> not be scanned.
The exception to that rule is if some other directory
Test is more explicitly specified as an include; I
think this is handled as well as can be in
couldHoldIncluded().
> Not sure whether this change does exactly that.
>
> I am not sure exactly what the semantics of isDeeper
> are ?
This method does as little as it has to. When this
(private) method is called, other methods have
determined the matching as well as we already have
had. isDeeper defers to SelectorUtils to return
tokenized path Vectors... if the pattern Vector
contains "**" it is infinitely deep and thus is
deeper, otherwise the pattern Vector must contain more
tokens than the name in order to be considered deeper.
Thus if we have no patterns that match files at
deeper levels than we have already reached, we do not
scan.
Hope this clears up a bit,
Matt
>
> Cheers,
>
> Antoine
>
> mbenson@apache.org wrote:
>
>
> >mbenson 2005/03/02 14:43:54
> >
> > Modified: src/main/org/apache/tools/ant
> DirectoryScanner.java
> > Log:
> > Stop scanning directories where we match the
> directory but know based
> > on the pattern that we will never match any of
> its contents.
> >....
> > /**
> > + * Verify that a pattern specifies files
> deeper
> > + * than the level of the specified file.
> > + * @param pattern the pattern to check.
> > + * @param name the name to check.
> > + * @return whether the pattern is deeper
> than the name.
> > + * @since Ant 1.6.3
> > + */
> > + private boolean isDeeper(String pattern,
> String name) {
> > + Vector p =
> SelectorUtils.tokenizePath(pattern);
> > + Vector n =
> SelectorUtils.tokenizePath(name);
> > + return p.contains("**") || p.size() >
> n.size();
> > + }
> > +
> >
> >
>
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> dev-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> dev-help@ant.apache.org
>
>
__________________________________
Celebrate Yahoo!'s 10th Birthday!
Yahoo! Netrospective: 100 Moments of the Web
http://birthday.yahoo.com/netrospective/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: cvs commit: ant/src/main/org/apache/tools/ant DirectoryScanner.java
Posted by Antoine Levy-Lambert <an...@gmx.de>.
Hello Matt and others,
I had thought about this issue of optimizing pattern scanning.
DirectoryScanner used to be written so that if an exclude pattern looks like
foo/bar/** scanning stops in foo/bar.
Actually if an exclude pattern is like **/Test/**,
every time a directory Test is encountered it should not be scanned.
Not sure whether this change does exactly that.
I am not sure exactly what the semantics of isDeeper are ?
Cheers,
Antoine
mbenson@apache.org wrote:
>mbenson 2005/03/02 14:43:54
>
> Modified: src/main/org/apache/tools/ant DirectoryScanner.java
> Log:
> Stop scanning directories where we match the directory but know based
> on the pattern that we will never match any of its contents.
>....
> /**
> + * Verify that a pattern specifies files deeper
> + * than the level of the specified file.
> + * @param pattern the pattern to check.
> + * @param name the name to check.
> + * @return whether the pattern is deeper than the name.
> + * @since Ant 1.6.3
> + */
> + private boolean isDeeper(String pattern, String name) {
> + Vector p = SelectorUtils.tokenizePath(pattern);
> + Vector n = SelectorUtils.tokenizePath(name);
> + return p.contains("**") || p.size() > n.size();
> + }
> +
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org