Author: bodewig
Date: Thu Oct 16 20:49:54 2008
New Revision: 705452
URL: http://svn.apache.org/viewvc?rev=705452&view=rev
Log:
optimize handling of package names
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java?rev=705452&r1=705451&r2=705452&view=diff
==============================================================================
---
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
(original)
+++
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
Thu Oct 16 20:49:54 2008
@@ -88,6 +88,10 @@
*/
static final String FILE_STRING = "File ";
/**
+ * Length of token to identify the word file in the rdiff log
+ */
+ static final int FILE_STRING_LENGTH = FILE_STRING.length();
+ /**
* Token to identify the word file in the rdiff log
*/
static final String TO_STRING = " to ";
@@ -151,6 +155,16 @@
private List packageNames = new ArrayList();
/**
+ * temporary list of "File:" + package name + "/" for all packages.
+ */
+ private String[] packageNamePrefixes = null;
+
+ /**
+ * temporary list of length values for prefixes.
+ */
+ private int[] packageNamePrefixLengths = null;
+
+ /**
* The package/module to analyze.
* @param p the name of the package to analyse
*/
@@ -246,20 +260,7 @@
setCommand("");
File tmpFile = null;
try {
- if (mypackage != null) {
- // support multiple packages
- StringTokenizer myTokenizer = new StringTokenizer(mypackage);
- while (myTokenizer.hasMoreTokens()) {
- String pack = myTokenizer.nextToken();
- packageNames.add(pack);
- addCommandArgument(pack);
- }
- }
- for (Iterator iter = getModules().iterator(); iter.hasNext();) {
- AbstractCvsTask.Module m = (AbstractCvsTask.Module)
iter.next();
- packageNames.add(m.getName());
- // will be added to command line in super.execute()
- }
+ handlePackageNames();
tmpFile = FILE_UTILS.createTempFile("cvstagdiff", ".log", null,
true, true);
@@ -275,6 +276,8 @@
writeTagDiff(entries);
} finally {
+ packageNamePrefixes = null;
+ packageNamePrefixLengths = null;
packageNames.clear();
if (tmpFile != null) {
tmpFile.delete();
@@ -316,7 +319,8 @@
String line = reader.readLine();
while (null != line) {
- line = removePackageName(line, packageNames);
+ line = removePackageName(line, packageNamePrefixes,
+ packageNamePrefixLengths);
if (line != null) {
// use || in a perl like fashion
boolean processed
@@ -514,27 +518,55 @@
}
/**
+ * collects package names from the package attribute and nested
+ * module elements.
+ */
+ private void handlePackageNames() {
+ if (mypackage != null) {
+ // support multiple packages
+ StringTokenizer myTokenizer = new StringTokenizer(mypackage);
+ while (myTokenizer.hasMoreTokens()) {
+ String pack = myTokenizer.nextToken();
+ packageNames.add(pack);
+ addCommandArgument(pack);
+ }
+ }
+ for (Iterator iter = getModules().iterator(); iter.hasNext();) {
+ AbstractCvsTask.Module m = (AbstractCvsTask.Module) iter.next();
+ packageNames.add(m.getName());
+ // will be added to command line in super.execute()
+ }
+ packageNamePrefixes = new String[packageNames.size()];
+ packageNamePrefixLengths = new int[packageNames.size()];
+ for (int i = 0; i < packageNamePrefixes.length; i++) {
+ packageNamePrefixes[i] = FILE_STRING + packageNames.get(i) + "/";
+ packageNamePrefixLengths[i] = packageNamePrefixes[i].length();
+ }
+ }
+
+
+ /**
* removes a "File: module/" prefix if present.
*
* @return null if the line was shorter than expected.
*/
- private static String removePackageName(String line, List packageNames) {
+ private static String removePackageName(String line,
+ String[] packagePrefixes,
+ int[] prefixLengths) {
+ if (line.length() < FILE_STRING_LENGTH) {
+ return null;
+ }
boolean matched = false;
- for (Iterator iter = packageNames.iterator(); iter.hasNext(); ) {
- String toBeRemoved = FILE_STRING + iter.next() + "/";
- int len = toBeRemoved.length();
- if (line.length() > len) {
- if (line.startsWith(toBeRemoved)) {
- matched = true;
- line = line.substring(len);
- break;
- }
+ for (int i = 0; i < packagePrefixes.length; i++) {
+ if (line.startsWith(packagePrefixes[i])) {
+ matched = true;
+ line = line.substring(prefixLengths[i]);
+ break;
}
}
- if (!matched && line.length() > FILE_STRING.length()) {
- line = line.substring(FILE_STRING.length());
- matched = true;
+ if (!matched) {
+ line = line.substring(FILE_STRING_LENGTH);
}
- return !matched ? null : line;
+ return line;
}
}
Modified:
ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history?rev=705452&r1=705451&r2=705452&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history
(original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history
Thu Oct 16 20:49:54 2008
@@ -16,3 +16,7 @@
O48f75282|stefan|/tmp/testoutput/*0|ant module 2||ant module 2
O48f75d32|stefan|/tmp/testoutput/*0|ant module 2||ant module 2
O48f75d34|stefan|/tmp/testoutput/*0|antmodule1||antmodule1
+O48f80394|stefan|/tmp/testoutput/*0|ant module 2||ant module 2
+O48f80395|stefan|/tmp/testoutput/*0|antmodule1||antmodule1
+O48f80ad6|stefan|/tmp/testoutput/*0|ant module 2||ant module 2
+O48f80ad7|stefan|/tmp/testoutput/*0|antmodule1||antmodule1