Browse Source

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>
stable-5.6
David Pursehouse 5 years ago
parent
commit
6a72f2943d
  1. 2
      org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
  2. 5
      org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
  3. 2
      org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesRule.java
  4. 4
      org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java
  5. 2
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java
  6. 2
      org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java

2
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java

@ -524,7 +524,7 @@ public class CommitCommand extends GitCommand<RevCommit> {
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);

5
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java

@ -833,7 +833,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
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 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
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())

2
org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesRule.java

@ -91,7 +91,7 @@ public class AttributesRule {
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 {

4
org.eclipse.jgit/src/org/eclipse/jgit/diff/SimilarityRenameDetector.java

@ -335,8 +335,8 @@ class SimilarityRenameDetector {
}
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);

2
org.eclipse.jgit/src/org/eclipse/jgit/transport/BasePackPushConnection.java

@ -391,7 +391,7 @@ public abstract class BasePackPushConnection extends BasePackConnection implemen
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

2
org.eclipse.jgit/src/org/eclipse/jgit/util/ChangeIdUtil.java

@ -181,7 +181,7 @@ public class ChangeIdUtil {
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));

Loading…
Cancel
Save