From b072b8d775230c8cbb1f6b674078ce0538dba208 Mon Sep 17 00:00:00 2001 From: David Ryan Date: Fri, 11 Oct 2024 13:02:37 +1100 Subject: [PATCH 1/2] Reduce argument allocations for checkArgument to reduce gc pressure. --- .../java/org/apache/tuweni/bytes/Utils.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bytes/src/main/java/org/apache/tuweni/bytes/Utils.java b/bytes/src/main/java/org/apache/tuweni/bytes/Utils.java index 06dee0575..689061907 100644 --- a/bytes/src/main/java/org/apache/tuweni/bytes/Utils.java +++ b/bytes/src/main/java/org/apache/tuweni/bytes/Utils.java @@ -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)); + } + } } From 14879783fb44898dca77bdcbc169a0b81826ad6f Mon Sep 17 00:00:00 2001 From: David Ryan Date: Mon, 14 Oct 2024 09:33:54 +1100 Subject: [PATCH 2/2] spotless changes. --- bytes/src/main/java/org/apache/tuweni/bytes/Utils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bytes/src/main/java/org/apache/tuweni/bytes/Utils.java b/bytes/src/main/java/org/apache/tuweni/bytes/Utils.java index 689061907..a2fa1edcf 100644 --- a/bytes/src/main/java/org/apache/tuweni/bytes/Utils.java +++ b/bytes/src/main/java/org/apache/tuweni/bytes/Utils.java @@ -56,7 +56,8 @@ static void checkArgument(boolean condition, String message, int arg1, int arg2, } @FormatMethod - static void checkArgument(boolean condition, String message, int arg1, int arg2, int arg3, int arg4) { + 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)); }