Use indexOf(char) and lastIndexOf(char) rather than String versions

An indexOf or lastIndexOf call with a single letter String can be
made more performant by switching to a call with a char argument.

Found with SonarLint.

As a side-effect of this change, we no longer need to suppress the
NON-NLS warnings.

Change-Id: Id44cb996bb74ed30edd560aa91fd8525aafdc8dd
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
David Pursehouse 2020-02-19 13:23:14 +09:00
parent 064834d350
commit 6a72f2943d
6 changed files with 9 additions and 8 deletions

View File

@ -524,7 +524,7 @@ private int lookupOnly(String pathString) {
int position = Collections.binarySearch(only, p);
if (position >= 0)
return position;
int l = p.lastIndexOf("/"); //$NON-NLS-1$
int l = p.lastIndexOf('/');
if (l < 1)
break;
p = p.substring(0, l);

View File

@ -833,7 +833,8 @@ private static String composeSquashMessage(boolean isSquash,
sb.append("# This is a combination of ").append(count)
.append(" commits.\n");
// Add the previous message without header (i.e first line)
sb.append(currSquashMessage.substring(currSquashMessage.indexOf("\n") + 1));
sb.append(currSquashMessage
.substring(currSquashMessage.indexOf('\n') + 1));
sb.append("\n");
if (isSquash) {
sb.append("# This is the ").append(count).append(ordinal)
@ -871,7 +872,7 @@ private static String getOrdinal(int count) {
static int parseSquashFixupSequenceCount(String currSquashMessage) {
String regex = "This is a combination of (.*) commits"; //$NON-NLS-1$
String firstLine = currSquashMessage.substring(0,
currSquashMessage.indexOf("\n")); //$NON-NLS-1$
currSquashMessage.indexOf('\n'));
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(firstLine);
if (!matcher.find())

View File

@ -91,7 +91,7 @@ private static List<Attribute> parseAttributes(String attributesLine) {
continue;
}
final int equalsIndex = attribute.indexOf("="); //$NON-NLS-1$
final int equalsIndex = attribute.indexOf('=');
if (equalsIndex == -1)
result.add(new Attribute(attribute, State.SET));
else {

View File

@ -335,8 +335,8 @@ private int buildMatrix(ProgressMonitor pm)
}
static int nameScore(String a, String b) {
int aDirLen = a.lastIndexOf("/") + 1; //$NON-NLS-1$
int bDirLen = b.lastIndexOf("/") + 1; //$NON-NLS-1$
int aDirLen = a.lastIndexOf('/') + 1;
int bDirLen = b.lastIndexOf('/') + 1;
int dirMin = Math.min(aDirLen, bDirLen);
int dirMax = Math.max(aDirLen, bDirLen);

View File

@ -391,7 +391,7 @@ private void readStatusReport(Map<String, RemoteRefUpdate> refUpdates)
refNameEnd = refLine.length();
} else if (refLine.startsWith("ng ")) { //$NON-NLS-1$
ok = false;
refNameEnd = refLine.indexOf(" ", 3); //$NON-NLS-1$
refNameEnd = refLine.indexOf(' ', 3);
}
if (refNameEnd == -1)
throw new PackProtocolException(MessageFormat.format(JGitText.get().unexpectedReportLine2

View File

@ -181,7 +181,7 @@ public static String insertId(String message, ObjectId changeId,
ret.append(CHANGE_ID);
ret.append(" I"); //$NON-NLS-1$
ret.append(ObjectId.toString(changeId));
int indexOfNextLineBreak = message.indexOf("\n", //$NON-NLS-1$
int indexOfNextLineBreak = message.indexOf('\n',
indexOfChangeId);
if (indexOfNextLineBreak > 0)
ret.append(message.substring(indexOfNextLineBreak));