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 c10ccc5dec
commit f08e80ffd6
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()) { if (a.length() != b.length()) {
return false; return false;
} }
for (int i = 0, j = 0; i < a.length(); ++i, ++j) { for (int i = 0; i < a.length(); ++i) {
if (!equalsIgnoreCase(a.charAt(i), b.charAt(j))) { if (!equalsIgnoreCase(a.charAt(i), b.charAt(i))) {
return false; return false;
} }
} }

View File

@ -240,6 +240,9 @@ public class AsciiStringCharacterTest {
assertThat(AsciiString.contentEqualsIgnoreCase(null, "foo"), is(false)); assertThat(AsciiString.contentEqualsIgnoreCase(null, "foo"), is(false));
assertThat(AsciiString.contentEqualsIgnoreCase("bar", null), is(false)); assertThat(AsciiString.contentEqualsIgnoreCase("bar", null), is(false));
assertThat(AsciiString.contentEqualsIgnoreCase("FoO", "fOo"), is(true)); 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) // Test variations (Ascii + String, Ascii + Ascii, String + Ascii)
assertThat(AsciiString.contentEqualsIgnoreCase(new AsciiString("FoO"), "fOo"), is(true)); assertThat(AsciiString.contentEqualsIgnoreCase(new AsciiString("FoO"), "fOo"), is(true));