Remove unnecessary loop variable from AsciiString. (#8711)

Motivation:

Incrementing two variables in sync is not necessary when only one will do.

Modifications:

- Remove `j` from `for` loop and replace with `i`.
- Add more unit testing scenarios to cover changed code.

Results:

Unnecessary variable removed.
This commit is contained in:
Derek Lewis 2019-01-14 23:33:29 -08:00 committed by Norman Maurer
parent 1b9cdc1f63
commit 4ac5264f0e
2 changed files with 5 additions and 2 deletions

View File

@ -1452,8 +1452,8 @@ public final class AsciiString implements CharSequence, Comparable<CharSequence>
if (a.length() != b.length()) {
return false;
}
for (int i = 0, j = 0; i < a.length(); ++i, ++j) {
if (!equalsIgnoreCase(a.charAt(i), b.charAt(j))) {
for (int i = 0; i < a.length(); ++i) {
if (!equalsIgnoreCase(a.charAt(i), b.charAt(i))) {
return false;
}
}

View File

@ -240,6 +240,9 @@ public class AsciiStringCharacterTest {
assertThat(AsciiString.contentEqualsIgnoreCase(null, "foo"), is(false));
assertThat(AsciiString.contentEqualsIgnoreCase("bar", null), is(false));
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true));
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "bar"), is(false));
assertThat(AsciiString.contentEqualsIgnoreCase("Foo", "foobar"), is(false));
assertThat(AsciiString.contentEqualsIgnoreCase("foobar", "Foo"), is(false));
// Test variations (Ascii + String, Ascii + Ascii, String + Ascii)
assertThat(AsciiString.contentEqualsIgnoreCase(new AsciiString("FoO"), "fOo"), is(true));