Browse Source

Redundant string length computations

master
Gintas Grigelionis 6 years ago
parent
commit
fffc2fde16
8 changed files with 28 additions and 41 deletions
  1. +1
    -1
      src/main/org/apache/tools/ant/Main.java
  2. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java
  3. +11
    -17
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java
  4. +10
    -16
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java
  5. +1
    -1
      src/main/org/apache/tools/ant/types/resources/JavaConstantResource.java
  6. +1
    -1
      src/main/org/apache/tools/ant/util/FileUtils.java
  7. +1
    -1
      src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java
  8. +2
    -3
      src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java

+ 1
- 1
src/main/org/apache/tools/ant/Main.java View File

@@ -549,7 +549,7 @@ public class Main implements AntMain {
* to help or not, so we simply look for the equals sign. * to help or not, so we simply look for the equals sign.
*/ */
final String arg = args[argPos]; final String arg = args[argPos];
String name = arg.substring(2, arg.length());
String name = arg.substring(2);
String value; String value;
final int posEq = name.indexOf('='); final int posEq = name.indexOf('=');
if (posEq > 0) { if (posEq > 0) {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java View File

@@ -171,7 +171,7 @@ class ChangeLogParser {
private void processFile(final String line) { private void processFile(final String line) {
if (!remote && line.startsWith("Working file:")) { if (!remote && line.startsWith("Working file:")) {
// CheckStyle:MagicNumber OFF // CheckStyle:MagicNumber OFF
file = line.substring(14, line.length());
file = line.substring(14);
// CheckStyle:MagicNumber ON // CheckStyle:MagicNumber ON
status = GET_REVISION; status = GET_REVISION;
} else if (remote && line.startsWith("RCS file:")) { } else if (remote && line.startsWith("RCS file:")) {


+ 11
- 17
src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandDeploymentTool.java View File

@@ -202,23 +202,17 @@ public class BorlandDeploymentTool extends GenericDeploymentTool
* @return the descriptor. * @return the descriptor.
*/ */
protected DescriptorHandler getBorlandDescriptorHandler(final File srcDir) { protected DescriptorHandler getBorlandDescriptorHandler(final File srcDir) {
DescriptorHandler handler =
new DescriptorHandler(getTask(), srcDir) {
@Override
protected void processElement() {
if ("type-storage".equals(currentElement)) {
// Get the filename of vendor specific descriptor
String fileNameWithMETA = currentText;
//trim the META_INF\ off of the file name
String fileName
= fileNameWithMETA.substring(META_DIR.length(),
fileNameWithMETA.length());
File descriptorFile = new File(srcDir, fileName);

ejbFiles.put(fileNameWithMETA, descriptorFile);
}
}
};
DescriptorHandler handler = new DescriptorHandler(getTask(), srcDir) {
@Override
protected void processElement() {
if ("type-storage".equals(currentElement)) {
// Get the filename of vendor specific descriptor
// trim the META_INF\ off of the file name
ejbFiles.put(currentText, new File(srcDir,
currentText.substring(META_DIR.length())));
}
}
};
handler.registerDTD(PUBLICID_BORLAND_EJB, handler.registerDTD(PUBLICID_BORLAND_EJB,
borlandDTD == null ? DEFAULT_BAS_DTD_LOCATION : borlandDTD); borlandDTD == null ? DEFAULT_BAS_DTD_LOCATION : borlandDTD);




+ 10
- 16
src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java View File

@@ -401,23 +401,17 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool {
* @return the descriptor. * @return the descriptor.
*/ */
protected DescriptorHandler getWeblogicDescriptorHandler(final File srcDir) { protected DescriptorHandler getWeblogicDescriptorHandler(final File srcDir) {
DescriptorHandler handler =
new DescriptorHandler(getTask(), srcDir) {
@Override
protected void processElement() {
if ("type-storage".equals(currentElement)) {
// Get the filename of vendor specific descriptor
String fileNameWithMETA = currentText;
//trim the META_INF\ off of the file name
String fileName
= fileNameWithMETA.substring(META_DIR.length(),
fileNameWithMETA.length());
File descriptorFile = new File(srcDir, fileName);

ejbFiles.put(fileNameWithMETA, descriptorFile);
}
DescriptorHandler handler = new DescriptorHandler(getTask(), srcDir) {
@Override
protected void processElement() {
if ("type-storage".equals(currentElement)) {
// Get the filename of vendor specific descriptor
// trim the META_INF\ off of the file name
ejbFiles.put(currentText, new File(srcDir,
currentText.substring(META_DIR.length())));
} }
};
}
};


handler.registerDTD(PUBLICID_WEBLOGIC_EJB510, DEFAULT_WL51_DTD_LOCATION); handler.registerDTD(PUBLICID_WEBLOGIC_EJB510, DEFAULT_WL51_DTD_LOCATION);
handler.registerDTD(PUBLICID_WEBLOGIC_EJB510, DEFAULT_WL60_51_DTD_LOCATION); handler.registerDTD(PUBLICID_WEBLOGIC_EJB510, DEFAULT_WL60_51_DTD_LOCATION);


+ 1
- 1
src/main/org/apache/tools/ant/types/resources/JavaConstantResource.java View File

@@ -47,7 +47,7 @@ public class JavaConstantResource extends AbstractClasspathResource {
throw new IOException("No class name in " + constant); throw new IOException("No class name in " + constant);
} }
String classname = constant.substring(0, index); String classname = constant.substring(0, index);
String fieldname = constant.substring(index + 1, constant.length());
String fieldname = constant.substring(index + 1);
try { try {
Class<?> clazz = Class<?> clazz =
cl != null cl != null


+ 1
- 1
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -858,7 +858,7 @@ public class FileUtils {
if (isDirectory) { if (isDirectory) {
directory = new StringBuilder(path.substring(index).replace(File.separatorChar, '.')); directory = new StringBuilder(path.substring(index).replace(File.separatorChar, '.'));
} else { } else {
int dirEnd = path.lastIndexOf(File.separatorChar, path.length());
int dirEnd = path.lastIndexOf(File.separatorChar);
if (dirEnd == -1 || dirEnd < index) { if (dirEnd == -1 || dirEnd < index) {
file = path.substring(index); file = path.substring(index);
} else { } else {


+ 1
- 1
src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java View File

@@ -724,7 +724,7 @@ public class LayoutPreservingProperties extends Properties {
setValue(null); setValue(null);
} else { } else {
name = text.substring(0, pos); name = text.substring(0, pos);
setValue(text.substring(pos + 1, text.length()));
setValue(text.substring(pos + 1));
} }
// trim leading whitespace only // trim leading whitespace only
name = stripStart(name, " \t\f"); name = stripStart(name, " \t\f");


+ 2
- 3
src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java View File

@@ -229,7 +229,7 @@ public class XmlPropertyTest {
assertNotEquals(assertMsg + " Object ID does not exist.", null, obj); assertNotEquals(assertMsg + " Object ID does not exist.", null, obj);


// What is the property supposed to be? // What is the property supposed to be?
propertyValue = propertyValue.substring(3, propertyValue.length());
propertyValue = propertyValue.substring(3);
if (propertyValue.equals("path")) { if (propertyValue.equals("path")) {
assertThat(assertMsg + " Path ID is a " + obj.getClass().getName(), assertThat(assertMsg + " Path ID is a " + obj.getClass().getName(),
obj, instanceOf(Path.class)); obj, instanceOf(Path.class));
@@ -243,8 +243,7 @@ public class XmlPropertyTest {
// The property is the name of a file. We are testing // The property is the name of a file. We are testing
// a location attribute, so we need to resolve the given // a location attribute, so we need to resolve the given
// file name in the provided folder. // file name in the provided folder.
String fileName =
propertyValue.substring(5, propertyValue.length());
String fileName = propertyValue.substring(5);
File f = new File(workingDir, fileName); File f = new File(workingDir, fileName);
propertyValue = f.getAbsolutePath(); propertyValue = f.getAbsolutePath();
} }


Loading…
Cancel
Save