Polish: String function use should be optimized for single characters

This commit is contained in:
igor-suhorukov
2018-02-25 22:34:35 +03:00
committed by Juergen Hoeller
parent 9c55dd5961
commit 49fd724d8f
31 changed files with 42 additions and 42 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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)));
}