Skip to content

String function optimizing for single characters #11680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private Map<String, Object> parseJson(String base64) {
}

public byte[] getContent() {
return this.encoded.substring(0, this.encoded.lastIndexOf(".")).getBytes();
return this.encoded.substring(0, this.encoded.lastIndexOf('.')).getBytes();
}

public byte[] getSignature() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public AuditEvent(Instant timestamp, String principal, String type,
private static Map<String, Object> convert(String[] data) {
Map<String, Object> result = new HashMap<>();
for (String entry : data) {
int index = entry.indexOf("=");
int index = entry.indexOf('=');
if (index != -1) {
result.put(entry.substring(0, index), entry.substring(index + 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ private String parseUsernameAndPassword(String input) {
}

private String parseVirtualHost(String input) {
int hostIndex = input.indexOf("/");
int hostIndex = input.indexOf('/');
if (hostIndex >= 0) {
this.virtualHost = input.substring(hostIndex + 1);
if (this.virtualHost.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected ConnectionInfo parseUrl(String url) {
String password = null;
if (uri.getUserInfo() != null) {
password = uri.getUserInfo();
int index = password.lastIndexOf(":");
int index = password.lastIndexOf(':');
if (index >= 0) {
password = password.substring(index + 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class DataSourceBeanCreationFailureAnalyzer
protected FailureAnalysis analyze(Throwable rootFailure,
DataSourceBeanCreationException cause) {
String message = cause.getMessage();
String description = message.substring(0, message.indexOf(".")).trim();
String action = message.substring(message.indexOf(".") + 1).trim();
String description = message.substring(0, message.indexOf('.')).trim();
String action = message.substring(message.indexOf('.') + 1).trim();
return new FailureAnalysis(description, action, cause);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public String getPath(String path) {

public String getServletPrefix() {
String result = this.path;
int index = result.indexOf("*");
int index = result.indexOf('*');
if (index != -1) {
result = result.substring(0, index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private String extractFileName(Header header) {
int start = value.indexOf(FILENAME_HEADER_PREFIX);
if (start != -1) {
value = value.substring(start + FILENAME_HEADER_PREFIX.length());
int end = value.indexOf("\"");
int end = value.indexOf('\"');
if (end != -1) {
return value.substring(0, end);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
ConfigurableEnvironment environment = event.getEnvironment();
String url = cleanRemoteUrl(environment.getProperty(NON_OPTION_ARGS));
Assert.state(StringUtils.hasLength(url), "No remote URL specified");
Assert.state(url.indexOf(",") == -1, "Multiple URLs specified");
Assert.state(url.indexOf(',') == -1, "Multiple URLs specified");
try {
new URI(url);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private Class<?> scanPackage(String source) {
}

private String getParentPackage(String sourcePackage) {
int lastDot = sourcePackage.lastIndexOf(".");
int lastDot = sourcePackage.lastIndexOf('.');
return (lastDot == -1 ? "" : sourcePackage.substring(0, lastDot));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private static Map<String, Object> getOrAdd(MutablePropertySources sources,
}

private static int getSeparatorIndex(String pair) {
int colonIndex = pair.indexOf(":");
int equalIndex = pair.indexOf("=");
int colonIndex = pair.indexOf(':');
int equalIndex = pair.indexOf('=');
if (colonIndex == -1) {
return equalIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ public static Pair parse(String pair) {
}

private static int getSeparatorIndex(String pair) {
int colonIndex = pair.indexOf(":");
int equalIndex = pair.indexOf("=");
int colonIndex = pair.indexOf(':');
int equalIndex = pair.indexOf('=');
if (colonIndex == -1) {
return equalIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String getShortDescription(String description) {
if (description == null) {
return null;
}
int dot = description.indexOf(".");
int dot = description.indexOf('.');
if (dot != -1) {
BreakIterator breakIterator = BreakIterator.getSentenceInstance(Locale.US);
breakIterator.setText(description);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private Object getFactoryValue(ExpressionTree expression, Object factoryValue) {
Object instance = expression.getInstance();
if (instance != null && instance.toString().startsWith(DURATION_OF)) {
String type = instance.toString();
type = type.substring(DURATION_OF.length(), type.indexOf("("));
type = type.substring(DURATION_OF.length(), type.indexOf('('));
String suffix = DURATION_SUFFIX.get(type);
return (suffix == null ? null : factoryValue + suffix);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ private void writeEntry(JarArchiveEntry entry, EntryWriter entryWriter)
else {
entry.setUnixMode(UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM);
}
if (parent.lastIndexOf("/") != -1) {
parent = parent.substring(0, parent.lastIndexOf("/") + 1);
if (parent.lastIndexOf('/') != -1) {
parent = parent.substring(0, parent.lastIndexOf('/') + 1);
if (!parent.isEmpty()) {
writeEntry(new JarArchiveEntry(parent), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ private List<Archive> getNestedArchives(String path) throws Exception {
// If home dir is same as parent archive, no need to add it twice.
return null;
}
int index = root.indexOf("!");
int index = root.indexOf('!');
if (index != -1) {
File file = new File(this.home, root.substring(0, index));
if (root.startsWith("jar:file:")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ protected Archive getNestedArchive(Entry entry) throws IOException {

private Archive getUnpackedNestedArchive(JarEntry jarEntry) throws IOException {
String name = jarEntry.getName();
if (name.lastIndexOf("/") != -1) {
name = name.substring(name.lastIndexOf("/") + 1);
if (name.lastIndexOf('/') != -1) {
name = name.substring(name.lastIndexOf('/') + 1);
}
File file = new File(getTempUnpackFolder(), name);
if (!file.exists() || file.length() != jarEntry.getSize()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private boolean isLoadCandidate(Resource resource) {
// a file list of the package content. We double check here that it's not
// actually a package.
String path = ((ClassPathResource) resource).getPath();
if (path.indexOf(".") == -1) {
if (path.indexOf('.') == -1) {
try {
return Package.getPackage(path) == null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private String getDefinitionDescription(String beanName, BeanDefinition definiti
private String[] extractBeanNames(NoUniqueBeanDefinitionException cause) {
if (cause.getMessage().indexOf("but found") > -1) {
return StringUtils.commaDelimitedListToStringArray(cause.getMessage()
.substring(cause.getMessage().lastIndexOf(":") + 1).trim());
.substring(cause.getMessage().lastIndexOf(':') + 1).trim());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private String getValue(String source, String defaultValue) {
if (value != null) {
return value;
}
int lastDot = source.lastIndexOf(".");
int lastDot = source.lastIndexOf('.');
if (lastDot > 0) {
String prefix = source.substring(0, lastDot + 1);
return this.environment.getProperty(prefix + source.substring(lastDot + 1),
Expand Down