Browse Source

optimize dependset by not comparing each target with each source but

only the oldest target.

Submitted by:	mrezaei@starpoint.com

I've also swapped the order of handling sourcefilesets and
sourcefilelists as filelists are a lot less expensive than filesets.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271455 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
63eed537b6
1 changed files with 51 additions and 44 deletions
  1. +51
    -44
      src/main/org/apache/tools/ant/taskdefs/DependSet.java

+ 51
- 44
src/main/org/apache/tools/ant/taskdefs/DependSet.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -179,6 +179,8 @@ public class DependSet extends MatchingTask {
// Grab all the target files specified via filesets // Grab all the target files specified via filesets
// //
Vector allTargets = new Vector(); Vector allTargets = new Vector();
long oldestTargetTime = 0;
File oldestTarget = null;
Enumeration enumTargetSets = targetFileSets.elements(); Enumeration enumTargetSets = targetFileSets.elements();
while (enumTargetSets.hasMoreElements()) { while (enumTargetSets.hasMoreElements()) {
@@ -195,6 +197,12 @@ public class DependSet extends MatchingTask {
log("Warning: "+targetFiles[i]+" modified in the future.", log("Warning: "+targetFiles[i]+" modified in the future.",
Project.MSG_WARN); Project.MSG_WARN);
} }

if (oldestTarget == null ||
dest.lastModified() < oldestTargetTime) {
oldestTargetTime = dest.lastModified();
oldestTarget = dest;
}
} }
} }


@@ -223,81 +231,80 @@ public class DependSet extends MatchingTask {
log("Warning: "+targetFiles[i]+" modified in the future.", log("Warning: "+targetFiles[i]+" modified in the future.",
Project.MSG_WARN); Project.MSG_WARN);
} }
if (oldestTarget == null ||
dest.lastModified() < oldestTargetTime) {
oldestTargetTime = dest.lastModified();
oldestTarget = dest;
}
} }
} }
if (oldestTarget != null) {
log(oldestTarget + " is oldest target file", Project.MSG_VERBOSE);
} else {
// no target files, then we cannot remove any target files and
// skip the following tests right away
upToDate = false;
}


// //
// Check targets vs source files specified via filesets
// Check targets vs source files specified via filelists
// //
if (upToDate) { if (upToDate) {
Enumeration enumSourceSets = sourceFileSets.elements();
while (upToDate && enumSourceSets.hasMoreElements()) {
Enumeration enumSourceLists = sourceFileLists.elements();
while (upToDate && enumSourceLists.hasMoreElements()) {
FileSet sourceFS = (FileSet) enumSourceSets.nextElement();
DirectoryScanner sourceDS = sourceFS.getDirectoryScanner(project);
String[] sourceFiles = sourceDS.getIncludedFiles();
FileList sourceFL = (FileList) enumSourceLists.nextElement();
String[] sourceFiles = sourceFL.getFiles(project);


for (int i=0; upToDate && i < sourceFiles.length; i++) {
File src = new File(sourceFS.getDir(project), sourceFiles[i]);
int i = 0;
do {
File src = new File(sourceFL.getDir(project), sourceFiles[i]);


if (src.lastModified() > now) { if (src.lastModified() > now) {
log("Warning: "+sourceFiles[i]+" modified in the future.", log("Warning: "+sourceFiles[i]+" modified in the future.",
Project.MSG_WARN); Project.MSG_WARN);
} }


Enumeration enumTargets = allTargets.elements();
while (upToDate && enumTargets.hasMoreElements()) {
File dest = (File)enumTargets.nextElement();
if (src.lastModified() > dest.lastModified()) {
log(dest.getPath() + " is out of date with respect to " +
sourceFiles[i], Project.MSG_VERBOSE);
upToDate = false;
if (!src.exists()) {
log(sourceFiles[i]+ " does not exist.", Project.MSG_VERBOSE);
upToDate = false;
break;
}


}
if (src.lastModified() > oldestTargetTime) {
upToDate = false;
log(oldestTarget + " is out of date with respect to " +
sourceFiles[i], Project.MSG_VERBOSE);
} }
}
} while (upToDate && (++i < sourceFiles.length) );
} }
} }


// //
// Check targets vs source files specified via filelists
// Check targets vs source files specified via filesets
// //
if (upToDate) { if (upToDate) {
Enumeration enumSourceLists = sourceFileLists.elements();
while (upToDate && enumSourceLists.hasMoreElements()) {
Enumeration enumSourceSets = sourceFileSets.elements();
while (upToDate && enumSourceSets.hasMoreElements()) {
FileList sourceFL = (FileList) enumSourceLists.nextElement();
String[] sourceFiles = sourceFL.getFiles(project);
FileSet sourceFS = (FileSet) enumSourceSets.nextElement();
DirectoryScanner sourceDS = sourceFS.getDirectoryScanner(project);
String[] sourceFiles = sourceDS.getIncludedFiles();


int i = 0;
do {
File src = new File(sourceFL.getDir(project), sourceFiles[i]);
for (int i=0; upToDate && i < sourceFiles.length; i++) {
File src = new File(sourceFS.getDir(project), sourceFiles[i]);


if (src.lastModified() > now) { if (src.lastModified() > now) {
log("Warning: "+sourceFiles[i]+" modified in the future.", log("Warning: "+sourceFiles[i]+" modified in the future.",
Project.MSG_WARN); Project.MSG_WARN);
} }


if (!src.exists()) {
log(sourceFiles[i]+ " does not exist.", Project.MSG_VERBOSE);
if (src.lastModified() > oldestTargetTime) {
upToDate = false; upToDate = false;
break;
log(oldestTarget + " is out of date with respect to " +
sourceFiles[i], Project.MSG_VERBOSE);
} }

Enumeration enumTargets = allTargets.elements();
while (upToDate && enumTargets.hasMoreElements()) {
File dest = (File)enumTargets.nextElement();
if (src.lastModified() > dest.lastModified()) {
log(dest.getPath() + " is out of date with respect to " +
sourceFiles[i], Project.MSG_VERBOSE);
upToDate = false;

}
}
} while (upToDate && (++i < sourceFiles.length) );
}
} }
} }




Loading…
Cancel
Save