Skip to content

Commit

Permalink
Remove unnecessary loop variable from AsciiString. (netty#8711)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lewisd32 authored and normanmaurer committed Jan 15, 2019
1 parent 1b9cdc1 commit 4ac5264
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions common/src/main/java/io/netty/util/AsciiString.java
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,8 @@ public static boolean contentEqualsIgnoreCase(CharSequence a, CharSequence b) {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ public void testEqualsIgnoreCase() {
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));
Expand Down

0 comments on commit 4ac5264

Please sign in to comment.