Skip to content

Commit

Permalink
Refactor if-else chains to switch in benchmark methods
Browse files Browse the repository at this point in the history
  • Loading branch information
panic08 committed Oct 7, 2024
1 parent afed86b commit 22a8041
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,21 @@ public void timeBagOfPrimitivesStreaming(int reps) throws IOException {
String stringValue = null;
while (jr.hasNext()) {
String name = jr.nextName();
if (name.equals("longValue")) {
longValue = jr.nextLong();
} else if (name.equals("intValue")) {
intValue = jr.nextInt();
} else if (name.equals("booleanValue")) {
booleanValue = jr.nextBoolean();
} else if (name.equals("stringValue")) {
stringValue = jr.nextString();
} else {
throw new IOException("Unexpected name: " + name);
switch (name) {
case "longValue":
longValue = jr.nextLong();
break;
case "intValue":
intValue = jr.nextInt();
break;
case "booleanValue":
booleanValue = jr.nextBoolean();
break;
case "stringValue":
stringValue = jr.nextString();
break;
default:
throw new IOException("Unexpected name: " + name);
}
}
jr.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,21 @@ public void timeCollectionsStreaming(int reps) throws IOException {
String stringValue = null;
while (jr.hasNext()) {
String name = jr.nextName();
if (name.equals("longValue")) {
longValue = jr.nextLong();
} else if (name.equals("intValue")) {
intValue = jr.nextInt();
} else if (name.equals("booleanValue")) {
booleanValue = jr.nextBoolean();
} else if (name.equals("stringValue")) {
stringValue = jr.nextString();
} else {
throw new IOException("Unexpected name: " + name);
switch (name) {
case "longValue":
longValue = jr.nextLong();
break;
case "intValue":
intValue = jr.nextInt();
break;
case "booleanValue":
booleanValue = jr.nextBoolean();
break;
case "stringValue":
stringValue = jr.nextString();
break;
default:
throw new IOException("Unexpected name: " + name);
}
}
jr.endObject();
Expand Down

0 comments on commit 22a8041

Please sign in to comment.