Skip to content

Commit

Permalink
Remove unnecessary code (netty#9303)
Browse files Browse the repository at this point in the history
Motivation:

There are is some unnecessary code (like toString() calls) which can be cleaned up.

Modifications:

- Remove not needed toString() calls
- Simplify subString(...) calls
- Remove some explicit casts when not needed.

Result:

Cleaner code
  • Loading branch information
slievrly authored and normanmaurer committed Jul 4, 2019
1 parent 707c95e commit a0656d2
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void addCombinedHeadersWhenEmpty() {
otherHeaders.add(HEADER_NAME, "a");
otherHeaders.add(HEADER_NAME, "b");
headers.add(otherHeaders);
assertEquals("a,b", headers.get(HEADER_NAME).toString());
assertEquals("a,b", headers.get(HEADER_NAME));
}

@Test
Expand All @@ -66,7 +66,7 @@ public void addCombinedHeadersWhenNotEmpty() {
otherHeaders.add(HEADER_NAME, "b");
otherHeaders.add(HEADER_NAME, "c");
headers.add(otherHeaders);
assertEquals("a,b,c", headers.get(HEADER_NAME).toString());
assertEquals("a,b,c", headers.get(HEADER_NAME));
}

@Test
Expand Down Expand Up @@ -99,7 +99,7 @@ public void setCombinedHeadersWhenNotEmpty() {
otherHeaders.add(HEADER_NAME, "b");
otherHeaders.add(HEADER_NAME, "c");
headers.set(otherHeaders);
assertEquals("b,c", headers.get(HEADER_NAME).toString());
assertEquals("b,c", headers.get(HEADER_NAME));
}

@Test
Expand All @@ -110,7 +110,7 @@ public void addUncombinedHeaders() {
otherHeaders.add(HEADER_NAME, "b");
otherHeaders.add(HEADER_NAME, "c");
headers.add(otherHeaders);
assertEquals("a,b,c", headers.get(HEADER_NAME).toString());
assertEquals("a,b,c", headers.get(HEADER_NAME));
}

@Test
Expand All @@ -121,7 +121,7 @@ public void setUncombinedHeaders() {
otherHeaders.add(HEADER_NAME, "b");
otherHeaders.add(HEADER_NAME, "c");
headers.set(otherHeaders);
assertEquals("b,c", headers.get(HEADER_NAME).toString());
assertEquals("b,c", headers.get(HEADER_NAME));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void testEmptySplitContent() throws Exception {
assertEncodedResponse(ch);

ch.writeOutbound(LastHttpContent.EMPTY_LAST_CONTENT);
HttpContent chunk = (HttpContent) ch.readOutbound();
HttpContent chunk = ch.readOutbound();
assertThat(ByteBufUtil.hexDump(chunk.content()), is("1f8b080000000000000003000000000000000000"));
assertThat(chunk, is(instanceOf(HttpContent.class)));
chunk.release();
Expand Down Expand Up @@ -423,7 +423,7 @@ public void testIdentity() throws Exception {
res.headers().set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.IDENTITY);
assertTrue(ch.writeOutbound(res));

FullHttpResponse response = (FullHttpResponse) ch.readOutbound();
FullHttpResponse response = ch.readOutbound();
assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
assertEquals(HttpHeaderValues.IDENTITY.toString(), response.headers().get(HttpHeaderNames.CONTENT_ENCODING));
assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII));
Expand All @@ -445,7 +445,7 @@ public void testCustomEncoding() throws Exception {
res.headers().set(HttpHeaderNames.CONTENT_ENCODING, "ascii");
assertTrue(ch.writeOutbound(res));

FullHttpResponse response = (FullHttpResponse) ch.readOutbound();
FullHttpResponse response = ch.readOutbound();
assertEquals(String.valueOf(len), response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
assertEquals("ascii", response.headers().get(HttpHeaderNames.CONTENT_ENCODING));
assertEquals("Hello, World", response.content().toString(CharsetUtil.US_ASCII));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class XmlDecoder extends ByteToMessageDecoder {
private static final XmlDocumentEnd XML_DOCUMENT_END = XmlDocumentEnd.INSTANCE;

private final AsyncXMLStreamReader<AsyncByteArrayFeeder> streamReader = XML_INPUT_FACTORY.createAsyncForByteArray();
private final AsyncByteArrayFeeder streamFeeder = (AsyncByteArrayFeeder) streamReader.getInputFeeder();
private final AsyncByteArrayFeeder streamFeeder = streamReader.getInputFeeder();

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
assertTrue(ch.finish());
assertEquals(1, ch.readInbound());

ByteBuf buf = (ByteBuf) ch.readInbound();
ByteBuf buf = ch.readInbound();
assertEquals(Unpooled.wrappedBuffer(new byte[]{'0'}), buf);
buf.release();
assertNull(ch.readInbound());
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/io/netty/util/NetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ private static Integer sysctlGetInt(String sysctlKey) throws IOException {
if (line.startsWith(sysctlKey)) {
for (int i = line.length() - 1; i > sysctlKey.length(); --i) {
if (!Character.isDigit(line.charAt(i))) {
return Integer.valueOf(line.substring(i + 1, line.length()));
return Integer.valueOf(line.substring(i + 1));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static void load(String originalName, ClassLoader loader) {

int index = libname.lastIndexOf('.');
String prefix = libname.substring(0, index);
String suffix = libname.substring(index, libname.length());
String suffix = libname.substring(index);

tmpFile = File.createTempFile(prefix, suffix, WORKDIR);
in = url.openStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,8 @@ private static int bitMode0() {

// Last resort: guess from VM name and then fall back to most common 64-bit mode.
String vm = SystemPropertyUtil.get("java.vm.name", "").toLowerCase(Locale.US);
Pattern BIT_PATTERN = Pattern.compile("([1-9][0-9]+)-?bit");
Matcher m = BIT_PATTERN.matcher(vm);
Pattern bitPattern = Pattern.compile("([1-9][0-9]+)-?bit");
Matcher m = bitPattern.matcher(vm);
if (m.find()) {
return Integer.parseInt(m.group(1));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ protected void markWait(final long time) throws Exception {
return;
} else {
System.out.print("-");
continue;
}
}
}
Expand Down

0 comments on commit a0656d2

Please sign in to comment.