Skip to content

Commit

Permalink
Inline variables to make code more readable (#11565)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hyperxpro authored and chrisvest committed Aug 11, 2021
1 parent 00d1dfb commit 99bd589
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 22 deletions.
Expand Up @@ -298,17 +298,16 @@ public void lowestPrecedenceStateShouldBeDropped() throws Http2Exception {
// Stream 3 (hasn't been opened) should result in stream 5 being dropped.
// dropping stream 5 will distribute its weight to children (only 9)
setPriority(3, 9, weight3, false);
short newWeight9 = weight5;
verifyLowestPrecedenceStateShouldBeDropped3(weight3, weight7, newWeight9);
verifyLowestPrecedenceStateShouldBeDropped3(weight3, weight7, weight5);

// Stream 5's state has been discarded so we should be able to re-insert this state.
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.
short weight11 = (short) (weight9 - 1);
setPriority(11, 0, weight11, false);
verifyLowestPrecedenceStateShouldBeDropped5(weight7, newWeight9, weight11);
verifyLowestPrecedenceStateShouldBeDropped5(weight7, weight5, weight11);
}

private void verifyLowestPrecedenceStateShouldBeDropped1(short weight3, short weight5, short weight7) {
Expand Down
Expand Up @@ -341,7 +341,6 @@ private void writeBlockData(ByteBuf out) {
final Bzip2BitWriter writer = this.writer;
final int[][] huffmanMergedCodeSymbols = this.huffmanMergedCodeSymbols;
final byte[] selectors = this.selectors;
final char[] mtf = mtfBlock;
final int mtfLength = this.mtfLength;

int selectorIndex = 0;
Expand All @@ -350,7 +349,7 @@ private void writeBlockData(ByteBuf out) {
final int[] tableMergedCodeSymbols = huffmanMergedCodeSymbols[selectors[selectorIndex++]];

while (mtfIndex <= groupEnd) {
final int mergedCodeSymbol = tableMergedCodeSymbols[mtf[mtfIndex++]];
final int mergedCodeSymbol = tableMergedCodeSymbols[mtfBlock[mtfIndex++]];
writer.writeBits(out, mergedCodeSymbol >>> 24, mergedCodeSymbol);
}
}
Expand Down
Expand Up @@ -49,9 +49,8 @@ public ResourceLeakException(Throwable cause) {

@Override
public int hashCode() {
StackTraceElement[] trace = cachedStackTrace;
int hashCode = 0;
for (StackTraceElement e: trace) {
for (StackTraceElement e: cachedStackTrace) {
hashCode = hashCode * 31 + e.hashCode();
}
return hashCode;
Expand Down
Expand Up @@ -169,15 +169,13 @@ public void escapeCsvNull() {
@Test
public void escapeCsvEmpty() {
CharSequence value = "";
CharSequence expected = value;
escapeCsv(value, expected);
escapeCsv(value, value);
}

@Test
public void escapeCsvUnquoted() {
CharSequence value = "something";
CharSequence expected = value;
escapeCsv(value, expected);
escapeCsv(value, value);
}

@Test
Expand Down Expand Up @@ -253,8 +251,7 @@ public void escapeCsvAlreadyEscapedQuote() {
@Test
public void escapeCsvQuoted() {
CharSequence value = "\"foo,goo\"";
CharSequence expected = value;
escapeCsv(value, expected);
escapeCsv(value, value);
}

@Test
Expand Down
Expand Up @@ -165,14 +165,13 @@ private static int decodeHexNibble(final char c) {
}

private static int decodeHexNibbleWithCheck(final char c) {
final int index = c;
if (index >= HEX2B.length) {
if ((int) c >= HEX2B.length) {
return -1;
}
if (PlatformDependent.hasUnsafe()) {
return PlatformDependent.getByte(HEX2B, index);
return PlatformDependent.getByte(HEX2B, c);
}
return HEX2B[index];
return HEX2B[c];
}

}
Expand Up @@ -105,10 +105,7 @@ public String toString() {
}

public List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> domainSocket() {

List<TestsuitePermutation.BootstrapComboFactory<ServerBootstrap, Bootstrap>> list =
combo(serverDomainSocket(), clientDomainSocket());
return list;
return combo(serverDomainSocket(), clientDomainSocket());
}

public List<BootstrapFactory<ServerBootstrap>> serverDomainSocket() {
Expand Down

0 comments on commit 99bd589

Please sign in to comment.