Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce argument allocations for checkArgument to reduce gc pressure. #104

Merged
merged 11 commits into from
Oct 16, 2024
42 changes: 42 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,46 @@ 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));
}
}
}