Skip to content

Commit 6ceca63

Browse files
hyperxpronormanmaurer
authored andcommitted
Simplify redundant if-block (netty#12376)
Motivation: We can simplify redundant `if-blocks` to make the code look simpler. Modification: Replaced `if-block` with simpler `boolean` statements. Result: Simpler code
1 parent 9b8f817 commit 6ceca63

File tree

4 files changed

+12
-27
lines changed

4 files changed

+12
-27
lines changed

codec-dns/src/main/java/io/netty/handler/codec/dns/DatagramDnsResponse.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,10 @@ public boolean equals(Object obj) {
202202
}
203203

204204
if (recipient() == null) {
205-
if (that.recipient() != null) {
206-
return false;
207-
}
208-
} else if (!recipient().equals(that.recipient())) {
209-
return false;
205+
return that.recipient() == null;
206+
} else {
207+
return recipient().equals(that.recipient());
210208
}
211-
212-
return true;
213209
}
214210

215211
@Override

codec/src/main/java/io/netty/handler/codec/MessageAggregator.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,9 @@ public boolean acceptInboundMessage(Object msg) throws Exception {
106106
if (isStartMessage(in)) {
107107
aggregating = true;
108108
return true;
109-
} else if (aggregating && isContentMessage(in)) {
110-
return true;
109+
} else {
110+
return aggregating && isContentMessage(in);
111111
}
112-
113-
return false;
114112
}
115113

116114
/**

handler/src/main/java/io/netty/handler/timeout/IdleStateHandler.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,7 @@ private boolean hasOutputChanged(ChannelHandlerContext ctx, boolean first) {
450450
long flushProgress = buf.currentProgress();
451451
if (flushProgress != lastFlushProgress) {
452452
lastFlushProgress = flushProgress;
453-
454-
if (!first) {
455-
return true;
456-
}
453+
return !first;
457454
}
458455
}
459456
}

microbench/src/main/java/io/netty/microbenchmark/common/IsValidIpV6Benchmark.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,8 @@ public static boolean isValidIpV6AddressOld(String ipAddress) {
184184
// Check if we have an IPv4 ending
185185
if (numberOfPeriods > 0) {
186186
// There is a test case with 7 colons and valid ipv4 this should resolve it
187-
if (numberOfPeriods != 3 ||
188-
!(isValidIp4Word(word.toString()) && (numberOfColons < 7 || doubleColon))) {
189-
return false;
190-
}
187+
return numberOfPeriods == 3 &&
188+
(isValidIp4Word(word.toString()) && (numberOfColons < 7 || doubleColon));
191189
} else {
192190
// If we're at then end and we haven't had 7 colons then there is a
193191
// problem unless we encountered a doubleColon
@@ -199,16 +197,12 @@ public static boolean isValidIpV6AddressOld(String ipAddress) {
199197
// If we have an empty word at the end, it means we ended in either
200198
// a : or a .
201199
// If we did not end in :: then this is invalid
202-
if (ipAddress.charAt(endOffset - 1) == ':' &&
203-
ipAddress.charAt(endOffset - 2) != ':') {
204-
return false;
205-
}
206-
} else if (numberOfColons == 8 && ipAddress.charAt(startOffset) != ':') {
207-
return false;
200+
return ipAddress.charAt(endOffset - 1) != ':' ||
201+
ipAddress.charAt(endOffset - 2) == ':';
202+
} else {
203+
return numberOfColons != 8 || ipAddress.charAt(startOffset) == ':';
208204
}
209205
}
210-
211-
return true;
212206
}
213207

214208
// Tests

0 commit comments

Comments
 (0)