Skip to content

Commit d891ee2

Browse files
David Ryanmacfarla
andauthored
Reduce check argument args allocations (#10)
* Reduce argument allocations for checkArgument to reduce gc pressure. * spotless changes. --------- Co-authored-by: Sally MacFarlane <[email protected]>
1 parent 64e2413 commit d891ee2

File tree

1 file changed

+43
-0
lines changed
  • bytes/src/main/java/org/apache/tuweni/bytes

1 file changed

+43
-0
lines changed

bytes/src/main/java/org/apache/tuweni/bytes/Utils.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,47 @@ static void checkArgument(boolean condition, String message, Object... args) {
2626
throw new IllegalArgumentException(String.format(message, args));
2727
}
2828
}
29+
30+
@FormatMethod
31+
static void checkArgument(boolean condition, String message) {
32+
if (!condition) {
33+
throw new IllegalArgumentException(message);
34+
}
35+
}
36+
37+
@FormatMethod
38+
static void checkArgument(boolean condition, String message, int arg1) {
39+
if (!condition) {
40+
throw new IllegalArgumentException(String.format(message, arg1));
41+
}
42+
}
43+
44+
@FormatMethod
45+
static void checkArgument(boolean condition, String message, int arg1, int arg2) {
46+
if (!condition) {
47+
throw new IllegalArgumentException(String.format(message, arg1, arg2));
48+
}
49+
}
50+
51+
@FormatMethod
52+
static void checkArgument(boolean condition, String message, int arg1, int arg2, int arg3) {
53+
if (!condition) {
54+
throw new IllegalArgumentException(String.format(message, arg1, arg2, arg3));
55+
}
56+
}
57+
58+
@FormatMethod
59+
static void checkArgument(
60+
boolean condition, String message, int arg1, int arg2, int arg3, int arg4) {
61+
if (!condition) {
62+
throw new IllegalArgumentException(String.format(message, arg1, arg2, arg3, arg4));
63+
}
64+
}
65+
66+
@FormatMethod
67+
static void checkArgument(boolean condition, String message, long arg1) {
68+
if (!condition) {
69+
throw new IllegalArgumentException(String.format(message, arg1));
70+
}
71+
}
2972
}

0 commit comments

Comments
 (0)