Skip to content

Commit

Permalink
Reduce check argument args allocations (#10)
Browse files Browse the repository at this point in the history
* Reduce argument allocations for checkArgument to reduce gc pressure.

* spotless changes.

---------

Co-authored-by: Sally MacFarlane <[email protected]>
  • Loading branch information
David Ryan and macfarla authored Oct 14, 2024
1 parent 64e2413 commit d891ee2
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions bytes/src/main/java/org/apache/tuweni/bytes/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,47 @@ static void checkArgument(boolean condition, String message, Object... args) {
throw new IllegalArgumentException(String.format(message, args));
}
}

@FormatMethod
static void checkArgument(boolean condition, String message) {
if (!condition) {
throw new IllegalArgumentException(message);
}
}

@FormatMethod
static void checkArgument(boolean condition, String message, int arg1) {
if (!condition) {
throw new IllegalArgumentException(String.format(message, arg1));
}
}

@FormatMethod
static void checkArgument(boolean condition, String message, int arg1, int arg2) {
if (!condition) {
throw new IllegalArgumentException(String.format(message, arg1, arg2));
}
}

@FormatMethod
static void checkArgument(boolean condition, String message, int arg1, int arg2, int arg3) {
if (!condition) {
throw new IllegalArgumentException(String.format(message, arg1, arg2, arg3));
}
}

@FormatMethod
static void checkArgument(
boolean condition, String message, int arg1, int arg2, int arg3, int arg4) {
if (!condition) {
throw new IllegalArgumentException(String.format(message, arg1, arg2, arg3, arg4));
}
}

@FormatMethod
static void checkArgument(boolean condition, String message, long arg1) {
if (!condition) {
throw new IllegalArgumentException(String.format(message, arg1));
}
}
}

0 comments on commit d891ee2

Please sign in to comment.