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:
parent
064834d350
commit
6a72f2943d
|
@ -524,7 +524,7 @@ private int lookupOnly(String pathString) {
|
||||||
int position = Collections.binarySearch(only, p);
|
int position = Collections.binarySearch(only, p);
|
||||||
if (position >= 0)
|
if (position >= 0)
|
||||||
return position;
|
return position;
|
||||||
int l = p.lastIndexOf("/"); //$NON-NLS-1$
|
int l = p.lastIndexOf('/');
|
||||||
if (l < 1)
|
if (l < 1)
|
||||||
break;
|
break;
|
||||||
p = p.substring(0, l);
|
p = p.substring(0, l);
|
||||||
|
|
|
@ -833,7 +833,8 @@ private static String composeSquashMessage(boolean isSquash,
|
||||||
sb.append("# This is a combination of ").append(count)
|
sb.append("# This is a combination of ").append(count)
|
||||||
.append(" commits.\n");
|
.append(" commits.\n");
|
||||||
// Add the previous message without header (i.e first line)
|
// 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");
|
sb.append("\n");
|
||||||
if (isSquash) {
|
if (isSquash) {
|
||||||
sb.append("# This is the ").append(count).append(ordinal)
|
sb.append("# This is the ").append(count).append(ordinal)
|
||||||
|
@ -871,7 +872,7 @@ private static String getOrdinal(int count) {
|
||||||
static int parseSquashFixupSequenceCount(String currSquashMessage) {
|
static int parseSquashFixupSequenceCount(String currSquashMessage) {
|
||||||
String regex = "This is a combination of (.*) commits"; //$NON-NLS-1$
|
String regex = "This is a combination of (.*) commits"; //$NON-NLS-1$
|
||||||
String firstLine = currSquashMessage.substring(0,
|
String firstLine = currSquashMessage.substring(0,
|
||||||
currSquashMessage.indexOf("\n")); //$NON-NLS-1$
|
currSquashMessage.indexOf('\n'));
|
||||||
Pattern pattern = Pattern.compile(regex);
|
Pattern pattern = Pattern.compile(regex);
|
||||||
Matcher matcher = pattern.matcher(firstLine);
|
Matcher matcher = pattern.matcher(firstLine);
|
||||||
if (!matcher.find())
|
if (!matcher.find())
|
||||||
|
|
|
@ -91,7 +91,7 @@ private static List<Attribute> parseAttributes(String attributesLine) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int equalsIndex = attribute.indexOf("="); //$NON-NLS-1$
|
final int equalsIndex = attribute.indexOf('=');
|
||||||
if (equalsIndex == -1)
|
if (equalsIndex == -1)
|
||||||
result.add(new Attribute(attribute, State.SET));
|
result.add(new Attribute(attribute, State.SET));
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -335,8 +335,8 @@ private int buildMatrix(ProgressMonitor pm)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nameScore(String a, String b) {
|
static int nameScore(String a, String b) {
|
||||||
int aDirLen = a.lastIndexOf("/") + 1; //$NON-NLS-1$
|
int aDirLen = a.lastIndexOf('/') + 1;
|
||||||
int bDirLen = b.lastIndexOf("/") + 1; //$NON-NLS-1$
|
int bDirLen = b.lastIndexOf('/') + 1;
|
||||||
|
|
||||||
int dirMin = Math.min(aDirLen, bDirLen);
|
int dirMin = Math.min(aDirLen, bDirLen);
|
||||||
int dirMax = Math.max(aDirLen, bDirLen);
|
int dirMax = Math.max(aDirLen, bDirLen);
|
||||||
|
|
|
@ -391,7 +391,7 @@ private void readStatusReport(Map<String, RemoteRefUpdate> refUpdates)
|
||||||
refNameEnd = refLine.length();
|
refNameEnd = refLine.length();
|
||||||
} else if (refLine.startsWith("ng ")) { //$NON-NLS-1$
|
} else if (refLine.startsWith("ng ")) { //$NON-NLS-1$
|
||||||
ok = false;
|
ok = false;
|
||||||
refNameEnd = refLine.indexOf(" ", 3); //$NON-NLS-1$
|
refNameEnd = refLine.indexOf(' ', 3);
|
||||||
}
|
}
|
||||||
if (refNameEnd == -1)
|
if (refNameEnd == -1)
|
||||||
throw new PackProtocolException(MessageFormat.format(JGitText.get().unexpectedReportLine2
|
throw new PackProtocolException(MessageFormat.format(JGitText.get().unexpectedReportLine2
|
||||||
|
|
|
@ -181,7 +181,7 @@ public static String insertId(String message, ObjectId changeId,
|
||||||
ret.append(CHANGE_ID);
|
ret.append(CHANGE_ID);
|
||||||
ret.append(" I"); //$NON-NLS-1$
|
ret.append(" I"); //$NON-NLS-1$
|
||||||
ret.append(ObjectId.toString(changeId));
|
ret.append(ObjectId.toString(changeId));
|
||||||
int indexOfNextLineBreak = message.indexOf("\n", //$NON-NLS-1$
|
int indexOfNextLineBreak = message.indexOf('\n',
|
||||||
indexOfChangeId);
|
indexOfChangeId);
|
||||||
if (indexOfNextLineBreak > 0)
|
if (indexOfNextLineBreak > 0)
|
||||||
ret.append(message.substring(indexOfNextLineBreak));
|
ret.append(message.substring(indexOfNextLineBreak));
|
||||||
|
|
Loading…
Reference in New Issue