Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve filtering performance #212

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/main/org/apache/tools/ant/DirectoryScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,8 @@ private void scandir(final File dir, final TokenizedPath path, final boolean fas
return;
}
if (!followSymlinks) {
final ArrayList<String> noLinks = new ArrayList<>();
final String[] noLinks = new String[newFiles.length];
int noLinksCount = 0;
for (final String newFile : newFiles) {
final Path filePath;
if (dir == null) {
Expand All @@ -1228,10 +1229,10 @@ private void scandir(final File dir, final TokenizedPath path, final boolean fas
}
accountForNotFollowedSymlink(name, file);
} else {
noLinks.add(newFile);
noLinks[noLinksCount++] = newFile;
}
}
newFiles = noLinks.toArray(new String[0]);
newFiles = Arrays.copyOf(noLinks, noLinksCount);
} else {
directoryNamesFollowed.addFirst(dir.getName());
}
Expand Down Expand Up @@ -1788,16 +1789,17 @@ private synchronized void clearCaches() {
*/
private TokenizedPattern[] fillNonPatternSet(final Map<String, TokenizedPath> map,
final String[] patterns) {
final List<TokenizedPattern> al = new ArrayList<>(patterns.length);
final TokenizedPattern[] al = new TokenizedPattern[patterns.length];
int alCount = 0;
for (String pattern : patterns) {
if (SelectorUtils.hasWildcards(pattern)) {
al.add(new TokenizedPattern(pattern));
al[alCount++] = new TokenizedPattern(pattern);
} else {
final String s = isCaseSensitive() ? pattern : pattern.toUpperCase();
map.put(s, new TokenizedPath(s));
}
}
return al.toArray(new TokenizedPattern[0]);
return Arrays.copyOf(al, alCount);
}

/**
Expand Down
18 changes: 10 additions & 8 deletions src/main/org/apache/tools/ant/taskdefs/Copy.java
Original file line number Diff line number Diff line change
Expand Up @@ -771,15 +771,16 @@ protected Map<Resource, String[]> scan(final Resource[] fromResources, final Fil
*/
protected void buildMap(final File fromDir, final File toDir, final String[] names,
final FileNameMapper mapper, final Hashtable<String, String[]> map) {
String[] toCopy = null;
final String[] toCopy;
if (forceOverwrite) {
final List<String> v = new ArrayList<>();
final String[] v = new String[names.length];
int added = 0;
for (String name : names) {
if (mapper.mapFileName(name) != null) {
v.add(name);
v[added++] = name;
}
}
toCopy = v.toArray(new String[0]);
toCopy = Arrays.copyOf(v, added);
} else {
final SourceFileScanner ds = new SourceFileScanner(this);
toCopy = ds.restrict(names, fromDir, toDir, mapper, granularity);
Expand Down Expand Up @@ -816,15 +817,16 @@ protected void buildMap(final File fromDir, final File toDir, final String[] nam
protected Map<Resource, String[]> buildMap(final Resource[] fromResources, final File toDir,
final FileNameMapper mapper) {
final Map<Resource, String[]> map = new HashMap<>();
Resource[] toCopy;
final Resource[] toCopy;
if (forceOverwrite) {
final List<Resource> v = new ArrayList<>();
final Resource[] v = new Resource[fromResources.length];
int added = 0;
for (Resource rc : fromResources) {
if (mapper.mapFileName(rc.getName()) != null) {
v.add(rc);
v[added++] = rc;
}
}
toCopy = v.toArray(new Resource[0]);
toCopy = Arrays.copyOf(v, added);
} else {
toCopy = ResourceUtils.selectOutOfDateSources(this, fromResources, mapper,
name -> new FileResource(toDir, name), granularity);
Expand Down