Inline variables to make code more readable (#11565)

Motivation:
There are lots of redundant variable declarations which should be inlined to make good look better.

Modification:
Made variables inlined.

Result:
Less redundant variable and more readable code.
This commit is contained in:
Aayush Atharva 2021-08-11 17:05:48 +02:00 committed by Chris Vest
parent 00d1dfb686
commit 99bd5895dc
6 changed files with 12 additions and 22 deletions

View File

@ -298,17 +298,16 @@ public class WeightedFairQueueByteDistributorDependencyTreeTest extends
// Stream 3 (hasn't been opened) should result in stream 5 being dropped. // Stream 3 (hasn't been opened) should result in stream 5 being dropped.
// dropping stream 5 will distribute its weight to children (only 9) // dropping stream 5 will distribute its weight to children (only 9)
setPriority(3, 9, weight3, false); setPriority(3, 9, weight3, false);
short newWeight9 = weight5; verifyLowestPrecedenceStateShouldBeDropped3(weight3, weight7, weight5);
verifyLowestPrecedenceStateShouldBeDropped3(weight3, weight7, newWeight9);
// Stream 5's state has been discarded so we should be able to re-insert this state. // Stream 5's state has been discarded so we should be able to re-insert this state.
setPriority(5, 0, weight5, false); setPriority(5, 0, weight5, false);
verifyLowestPrecedenceStateShouldBeDropped4(weight5, weight7, newWeight9); verifyLowestPrecedenceStateShouldBeDropped4(weight5, weight7, weight5);
// All streams are at the same level, so stream ID should be used to drop the numeric lowest valued stream. // All streams are at the same level, so stream ID should be used to drop the numeric lowest valued stream.
short weight11 = (short) (weight9 - 1); short weight11 = (short) (weight9 - 1);
setPriority(11, 0, weight11, false); setPriority(11, 0, weight11, false);
verifyLowestPrecedenceStateShouldBeDropped5(weight7, newWeight9, weight11); verifyLowestPrecedenceStateShouldBeDropped5(weight7, weight5, weight11);
} }
private void verifyLowestPrecedenceStateShouldBeDropped1(short weight3, short weight5, short weight7) { private void verifyLowestPrecedenceStateShouldBeDropped1(short weight3, short weight5, short weight7) {

View File

@ -341,7 +341,6 @@ final class Bzip2HuffmanStageEncoder {
final Bzip2BitWriter writer = this.writer; final Bzip2BitWriter writer = this.writer;
final int[][] huffmanMergedCodeSymbols = this.huffmanMergedCodeSymbols; final int[][] huffmanMergedCodeSymbols = this.huffmanMergedCodeSymbols;
final byte[] selectors = this.selectors; final byte[] selectors = this.selectors;
final char[] mtf = mtfBlock;
final int mtfLength = this.mtfLength; final int mtfLength = this.mtfLength;
int selectorIndex = 0; int selectorIndex = 0;
@ -350,7 +349,7 @@ final class Bzip2HuffmanStageEncoder {
final int[] tableMergedCodeSymbols = huffmanMergedCodeSymbols[selectors[selectorIndex++]]; final int[] tableMergedCodeSymbols = huffmanMergedCodeSymbols[selectors[selectorIndex++]];
while (mtfIndex <= groupEnd) { while (mtfIndex <= groupEnd) {
final int mergedCodeSymbol = tableMergedCodeSymbols[mtf[mtfIndex++]]; final int mergedCodeSymbol = tableMergedCodeSymbols[mtfBlock[mtfIndex++]];
writer.writeBits(out, mergedCodeSymbol >>> 24, mergedCodeSymbol); writer.writeBits(out, mergedCodeSymbol >>> 24, mergedCodeSymbol);
} }
} }

View File

@ -49,9 +49,8 @@ public class ResourceLeakException extends RuntimeException {
@Override @Override
public int hashCode() { public int hashCode() {
StackTraceElement[] trace = cachedStackTrace;
int hashCode = 0; int hashCode = 0;
for (StackTraceElement e: trace) { for (StackTraceElement e: cachedStackTrace) {
hashCode = hashCode * 31 + e.hashCode(); hashCode = hashCode * 31 + e.hashCode();
} }
return hashCode; return hashCode;

View File

@ -169,15 +169,13 @@ public class StringUtilTest {
@Test @Test
public void escapeCsvEmpty() { public void escapeCsvEmpty() {
CharSequence value = ""; CharSequence value = "";
CharSequence expected = value; escapeCsv(value, value);
escapeCsv(value, expected);
} }
@Test @Test
public void escapeCsvUnquoted() { public void escapeCsvUnquoted() {
CharSequence value = "something"; CharSequence value = "something";
CharSequence expected = value; escapeCsv(value, value);
escapeCsv(value, expected);
} }
@Test @Test
@ -253,8 +251,7 @@ public class StringUtilTest {
@Test @Test
public void escapeCsvQuoted() { public void escapeCsvQuoted() {
CharSequence value = "\"foo,goo\""; CharSequence value = "\"foo,goo\"";
CharSequence expected = value; escapeCsv(value, value);
escapeCsv(value, expected);
} }
@Test @Test

View File

@ -165,14 +165,13 @@ public class DecodeHexBenchmark extends AbstractMicrobenchmark {
} }
private static int decodeHexNibbleWithCheck(final char c) { private static int decodeHexNibbleWithCheck(final char c) {
final int index = c; if ((int) c >= HEX2B.length) {
if (index >= HEX2B.length) {
return -1; return -1;
} }
if (PlatformDependent.hasUnsafe()) { if (PlatformDependent.hasUnsafe()) {
return PlatformDependent.getByte(HEX2B, index); return PlatformDependent.getByte(HEX2B, c);
} }
return HEX2B[index]; return HEX2B[c];
} }
} }

View File

@ -105,10 +105,7 @@ class KQueueSocketTestPermutation extends SocketTestPermutation {
} }
public List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> domainSocket() { public List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> domainSocket() {
return combo(serverDomainSocket(), clientDomainSocket());
List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> list =
combo(serverDomainSocket(), clientDomainSocket());
return list;
} }
public List<BootstrapFactory<ServerBootstrap>> serverDomainSocket() { public List<BootstrapFactory<ServerBootstrap>> serverDomainSocket() {