Polish: String function use should be optimized for single characters
This commit is contained in:
parent
9c55dd5961
commit
49fd724d8f
|
|
@ -421,7 +421,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
|||
String[] tokens = StringUtils.tokenizeToStringArray(this.pointcutExpression, " ");
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
String toMatch = tokens[i];
|
||||
int firstParenIndex = toMatch.indexOf("(");
|
||||
int firstParenIndex = toMatch.indexOf('(');
|
||||
if (firstParenIndex != -1) {
|
||||
toMatch = toMatch.substring(0, firstParenIndex);
|
||||
}
|
||||
|
|
@ -582,7 +582,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
|||
if (toMatch.startsWith("!")) {
|
||||
toMatch = toMatch.substring(1);
|
||||
}
|
||||
int firstParenIndex = toMatch.indexOf("(");
|
||||
int firstParenIndex = toMatch.indexOf('(');
|
||||
if (firstParenIndex != -1) {
|
||||
toMatch = toMatch.substring(0, firstParenIndex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public class AspectMetadata implements Serializable {
|
|||
*/
|
||||
private String findPerClause(Class<?> aspectClass) {
|
||||
String str = aspectClass.getAnnotation(Aspect.class).value();
|
||||
str = str.substring(str.indexOf("(") + 1);
|
||||
str = str.substring(str.indexOf('(') + 1);
|
||||
str = str.substring(0, str.length() - 1);
|
||||
return str;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -367,8 +367,8 @@ public abstract class BeanUtils {
|
|||
public static Method resolveSignature(String signature, Class<?> clazz) {
|
||||
Assert.hasText(signature, "'signature' must not be empty");
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
int firstParen = signature.indexOf("(");
|
||||
int lastParen = signature.indexOf(")");
|
||||
int firstParen = signature.indexOf('(');
|
||||
int lastParen = signature.indexOf(')');
|
||||
if (firstParen > -1 && lastParen == -1) {
|
||||
throw new IllegalArgumentException("Invalid method signature '" + signature +
|
||||
"': expected closing ')' for args list");
|
||||
|
|
|
|||
|
|
@ -317,7 +317,7 @@ class TypeConverterDelegate {
|
|||
|
||||
if (Enum.class == requiredType && this.targetObject != null) {
|
||||
// target type is declared as raw enum, treat the trimmed value as <enum.fqn>.FIELD_NAME
|
||||
int index = trimmedValue.lastIndexOf(".");
|
||||
int index = trimmedValue.lastIndexOf('.');
|
||||
if (index > - 1) {
|
||||
String enumType = trimmedValue.substring(0, index);
|
||||
String fieldName = trimmedValue.substring(index + 1);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class BeansDtdResolver implements EntityResolver {
|
|||
"] and system ID [" + systemId + "]");
|
||||
}
|
||||
if (systemId != null && systemId.endsWith(DTD_EXTENSION)) {
|
||||
int lastPathSeparator = systemId.lastIndexOf("/");
|
||||
int lastPathSeparator = systemId.lastIndexOf('/');
|
||||
int dtdNameStart = systemId.indexOf(DTD_NAME, lastPathSeparator);
|
||||
if (dtdNameStart != -1) {
|
||||
String dtdFile = DTD_NAME + DTD_EXTENSION;
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public class UtilNamespaceHandler extends NamespaceHandlerSupport {
|
|||
parserContext.getReaderContext().error("Attribute 'path' must not be empty", element);
|
||||
return;
|
||||
}
|
||||
int dotIndex = path.indexOf(".");
|
||||
int dotIndex = path.indexOf('.');
|
||||
if (dotIndex == -1) {
|
||||
parserContext.getReaderContext().error(
|
||||
"Attribute 'path' must follow pattern 'beanName.propertyName'", element);
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ class SimpleCommandLineArgsParser {
|
|||
String optionName;
|
||||
String optionValue = null;
|
||||
if (optionText.contains("=")) {
|
||||
optionName = optionText.substring(0, optionText.indexOf("="));
|
||||
optionValue = optionText.substring(optionText.indexOf("=")+1, optionText.length());
|
||||
optionName = optionText.substring(0, optionText.indexOf('='));
|
||||
optionValue = optionText.substring(optionText.indexOf('=')+1, optionText.length());
|
||||
}
|
||||
else {
|
||||
optionName = optionText;
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
|||
// Generally only look for a pattern after a prefix here,
|
||||
// and on Tomcat only after the "*/" separator for its "war:" protocol.
|
||||
int prefixEnd = (locationPattern.startsWith("war:") ? locationPattern.indexOf("*/") + 1 :
|
||||
locationPattern.indexOf(":") + 1);
|
||||
locationPattern.indexOf(':') + 1);
|
||||
if (getPathMatcher().isPattern(locationPattern.substring(prefixEnd))) {
|
||||
// a file pattern
|
||||
return findPathMatchingResources(locationPattern);
|
||||
|
|
@ -531,7 +531,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
|||
* @see #retrieveMatchingFiles
|
||||
*/
|
||||
protected String determineRootDir(String location) {
|
||||
int prefixEnd = location.indexOf(":") + 1;
|
||||
int prefixEnd = location.indexOf(':') + 1;
|
||||
int rootDirEnd = location.length();
|
||||
while (rootDirEnd > prefixEnd && getPathMatcher().isPattern(location.substring(prefixEnd, rootDirEnd))) {
|
||||
rootDirEnd = location.lastIndexOf('/', rootDirEnd - 2) + 1;
|
||||
|
|
|
|||
|
|
@ -638,7 +638,7 @@ public abstract class StringUtils {
|
|||
// first path element. This is necessary to correctly parse paths like
|
||||
// "file:core/../core/io/Resource.class", where the ".." should just
|
||||
// strip the first "core" directory while keeping the "file:" prefix.
|
||||
int prefixIndex = pathToUse.indexOf(":");
|
||||
int prefixIndex = pathToUse.indexOf(':');
|
||||
String prefix = "";
|
||||
if (prefixIndex != -1) {
|
||||
prefix = pathToUse.substring(0, prefixIndex + 1);
|
||||
|
|
|
|||
|
|
@ -346,7 +346,7 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider {
|
|||
else if (found.isEmpty()) {
|
||||
if (metaDataProcedureName != null && metaDataProcedureName.contains(".") &&
|
||||
!StringUtils.hasText(metaDataCatalogName)) {
|
||||
String packageName = metaDataProcedureName.substring(0, metaDataProcedureName.indexOf("."));
|
||||
String packageName = metaDataProcedureName.substring(0, metaDataProcedureName.indexOf('.'));
|
||||
throw new InvalidDataAccessApiUsageException(
|
||||
"Unable to determine the correct call signature for '" + metaDataProcedureName +
|
||||
"' - package name should be specified separately using '.withCatalogName(\"" +
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ public abstract class ScriptUtils {
|
|||
}
|
||||
else if (script.startsWith(commentPrefix, i)) {
|
||||
// Skip over any content from the start of the comment to the EOL
|
||||
int indexOfNextNewline = script.indexOf("\n", i);
|
||||
int indexOfNextNewline = script.indexOf('\n', i);
|
||||
if (indexOfNextNewline > i) {
|
||||
i = indexOfNextNewline;
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ public class StompDecoder {
|
|||
private String unescape(String inString) {
|
||||
StringBuilder sb = new StringBuilder(inString.length());
|
||||
int pos = 0; // position in the old string
|
||||
int index = inString.indexOf("\\");
|
||||
int index = inString.indexOf('\\');
|
||||
|
||||
while (index >= 0) {
|
||||
sb.append(inString.substring(pos, index));
|
||||
|
|
@ -285,7 +285,7 @@ public class StompDecoder {
|
|||
throw new StompConversionException("Illegal escape sequence at index " + index + ": " + inString);
|
||||
}
|
||||
pos = index + 2;
|
||||
index = inString.indexOf("\\", pos);
|
||||
index = inString.indexOf('\\', pos);
|
||||
}
|
||||
|
||||
sb.append(inString.substring(pos));
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ public class MethodMapTransactionAttributeSource
|
|||
*/
|
||||
public void addTransactionalMethod(String name, TransactionAttribute attr) {
|
||||
Assert.notNull(name, "Name must not be null");
|
||||
int lastDotIndex = name.lastIndexOf(".");
|
||||
int lastDotIndex = name.lastIndexOf('.');
|
||||
if (lastDotIndex == -1) {
|
||||
throw new IllegalArgumentException("'" + name + "' is not a valid method name: format is FQN.methodName");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@ public class ContentDisposition {
|
|||
}
|
||||
else if (attribute.equals("filename*") ) {
|
||||
filename = decodeHeaderFieldParam(value);
|
||||
charset = Charset.forName(value.substring(0, value.indexOf("'")));
|
||||
charset = Charset.forName(value.substring(0, value.indexOf('\'')));
|
||||
Assert.isTrue(UTF_8.equals(charset) || ISO_8859_1.equals(charset),
|
||||
"Charset should be UTF-8 or ISO-8859-1");
|
||||
}
|
||||
|
|
@ -362,8 +362,8 @@ public class ContentDisposition {
|
|||
*/
|
||||
private static String decodeHeaderFieldParam(String input) {
|
||||
Assert.notNull(input, "Input String should not be null");
|
||||
int firstQuoteIndex = input.indexOf("'");
|
||||
int secondQuoteIndex = input.indexOf("'", firstQuoteIndex + 1);
|
||||
int firstQuoteIndex = input.indexOf('\'');
|
||||
int secondQuoteIndex = input.indexOf('\'', firstQuoteIndex + 1);
|
||||
// US_ASCII
|
||||
if (firstQuoteIndex == -1 || secondQuoteIndex == -1) {
|
||||
return input;
|
||||
|
|
|
|||
|
|
@ -1277,7 +1277,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
|||
// Let's only bother with DateTimeFormatter parsing for long enough values.
|
||||
|
||||
// See https://stackoverflow.com/questions/12626699/if-modified-since-http-header-passed-by-ie9-includes-length
|
||||
int parametersIndex = headerValue.indexOf(";");
|
||||
int parametersIndex = headerValue.indexOf(';');
|
||||
if (parametersIndex != -1) {
|
||||
headerValue = headerValue.substring(0, parametersIndex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ class DefaultPathContainer implements PathContainer {
|
|||
|
||||
private static void parsePathParamValues(String input, Charset charset, MultiValueMap<String, String> output) {
|
||||
if (StringUtils.hasText(input)) {
|
||||
int index = input.indexOf("=");
|
||||
int index = input.indexOf('=');
|
||||
if (index != -1) {
|
||||
String name = input.substring(0, index);
|
||||
String value = input.substring(index + 1);
|
||||
|
|
|
|||
|
|
@ -101,9 +101,9 @@ public class CommonsMultipartFile implements MultipartFile, Serializable {
|
|||
}
|
||||
|
||||
// Check for Unix-style path
|
||||
int unixSep = filename.lastIndexOf("/");
|
||||
int unixSep = filename.lastIndexOf('/');
|
||||
// Check for Windows-style path
|
||||
int winSep = filename.lastIndexOf("\\");
|
||||
int winSep = filename.lastIndexOf('\\');
|
||||
// Cut off at latest possible point
|
||||
int pos = (winSep > unixSep ? winSep : unixSep);
|
||||
if (pos != -1) {
|
||||
|
|
|
|||
|
|
@ -769,8 +769,8 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
|||
}
|
||||
|
||||
private void adaptForwardedHost(String hostToUse) {
|
||||
int portSeparatorIdx = hostToUse.lastIndexOf(":");
|
||||
if (portSeparatorIdx > hostToUse.lastIndexOf("]")) {
|
||||
int portSeparatorIdx = hostToUse.lastIndexOf(':');
|
||||
if (portSeparatorIdx > hostToUse.lastIndexOf(']')) {
|
||||
host(hostToUse.substring(0, portSeparatorIdx));
|
||||
port(Integer.parseInt(hostToUse.substring(portSeparatorIdx + 1)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ public class AppCacheManifestTransformer extends ResourceTransformerSupport {
|
|||
}
|
||||
|
||||
private static boolean hasScheme(String line) {
|
||||
int index = line.indexOf(":");
|
||||
int index = line.indexOf(':');
|
||||
return (line.startsWith("//") || (index > 0 && !line.substring(0, index).contains("/")));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
|
|||
}
|
||||
|
||||
private boolean hasScheme(String link) {
|
||||
int schemeIndex = link.indexOf(":");
|
||||
int schemeIndex = link.indexOf(':');
|
||||
return (schemeIndex > 0 && !link.substring(0, schemeIndex).contains("/")) || link.indexOf("//") == 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -151,11 +151,11 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
|||
|
||||
private int getQueryIndex(String path) {
|
||||
int suffixIndex = path.length();
|
||||
int queryIndex = path.indexOf("?");
|
||||
int queryIndex = path.indexOf('?');
|
||||
if (queryIndex > 0) {
|
||||
suffixIndex = queryIndex;
|
||||
}
|
||||
int hashIndex = path.indexOf("#");
|
||||
int hashIndex = path.indexOf('#');
|
||||
if (hashIndex > 0) {
|
||||
suffixIndex = Math.min(suffixIndex, hashIndex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ public class WebJarsResourceResolver extends AbstractResourceResolver {
|
|||
protected String findWebJarResourcePath(String path) {
|
||||
try {
|
||||
int startOffset = (path.startsWith("/") ? 1 : 0);
|
||||
int endOffset = path.indexOf("/", 1);
|
||||
int endOffset = path.indexOf('/', 1);
|
||||
if (endOffset != -1) {
|
||||
String webjar = path.substring(startOffset, endOffset);
|
||||
String partialPath = path.substring(endOffset);
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ public class RedirectView extends AbstractUrlBasedView {
|
|||
return new StringBuilder(targetUrl);
|
||||
}
|
||||
|
||||
int index = targetUrl.indexOf("#");
|
||||
int index = targetUrl.indexOf('#');
|
||||
String fragment = (index > -1 ? targetUrl.substring(index) : null);
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ public class UrlFilenameViewController extends AbstractUrlViewController {
|
|||
*/
|
||||
protected String extractViewNameFromUrlPath(String uri) {
|
||||
int start = (uri.charAt(0) == '/' ? 1 : 0);
|
||||
int lastIndex = uri.lastIndexOf(".");
|
||||
int lastIndex = uri.lastIndexOf('.');
|
||||
int end = (lastIndex < 0 ? uri.length() : lastIndex);
|
||||
return uri.substring(start, end);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ public class AppCacheManifestTransformer extends ResourceTransformerSupport {
|
|||
}
|
||||
|
||||
private static boolean hasScheme(String line) {
|
||||
int index = line.indexOf(":");
|
||||
int index = line.indexOf(':');
|
||||
return (line.startsWith("//") || (index > 0 && !line.substring(0, index).contains("/")));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
|
|||
}
|
||||
|
||||
private boolean hasScheme(String link) {
|
||||
int schemeIndex = link.indexOf(":");
|
||||
int schemeIndex = link.indexOf(':');
|
||||
return (schemeIndex > 0 && !link.substring(0, schemeIndex).contains("/")) || link.indexOf("//") == 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -355,7 +355,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
|||
Charset charset = null;
|
||||
location = location.trim();
|
||||
if (location.startsWith(URL_RESOURCE_CHARSET_PREFIX)) {
|
||||
int endIndex = location.indexOf("]", URL_RESOURCE_CHARSET_PREFIX.length());
|
||||
int endIndex = location.indexOf(']', URL_RESOURCE_CHARSET_PREFIX.length());
|
||||
if (endIndex == -1) {
|
||||
throw new IllegalArgumentException("Invalid charset syntax in location: " + location);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean {
|
|||
}
|
||||
|
||||
private int getQueryParamsIndex(String url) {
|
||||
int index = url.indexOf("?");
|
||||
int index = url.indexOf('?');
|
||||
return (index > 0 ? index : url.length());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,11 +193,11 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
|
|||
|
||||
private int getEndPathIndex(String lookupPath) {
|
||||
int suffixIndex = lookupPath.length();
|
||||
int queryIndex = lookupPath.indexOf("?");
|
||||
int queryIndex = lookupPath.indexOf('?');
|
||||
if(queryIndex > 0) {
|
||||
suffixIndex = queryIndex;
|
||||
}
|
||||
int hashIndex = lookupPath.indexOf("#");
|
||||
int hashIndex = lookupPath.indexOf('#');
|
||||
if(hashIndex > 0) {
|
||||
suffixIndex = Math.min(suffixIndex, hashIndex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ public class WebJarsResourceResolver extends AbstractResourceResolver {
|
|||
@Nullable
|
||||
protected String findWebJarResourcePath(String path) {
|
||||
int startOffset = (path.startsWith("/") ? 1 : 0);
|
||||
int endOffset = path.indexOf("/", 1);
|
||||
int endOffset = path.indexOf('/', 1);
|
||||
if (endOffset != -1) {
|
||||
String webjar = path.substring(startOffset, endOffset);
|
||||
String partialPath = path.substring(endOffset + 1);
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
|
|||
StringTokenizer st = new StringTokenizer(propString, ",");
|
||||
while (st.hasMoreTokens()) {
|
||||
String tok = st.nextToken();
|
||||
int eqIdx = tok.indexOf("=");
|
||||
int eqIdx = tok.indexOf('=');
|
||||
if (eqIdx == -1) {
|
||||
throw new IllegalArgumentException("Expected = in attributes CSV string '" + propString + "'");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue