From 320f454e499a61aae7ef6462f952d10ea53aedde Mon Sep 17 00:00:00 2001 From: ghm Date: Tue, 5 Nov 2024 08:08:25 -0800 Subject: [PATCH] Remove some boxing via Optional in `getResultType`. Not a big deal, but this is an extra allocation and a bit obfuscated. (I almost want a Klippy for this pattern; I've seen it in readability reviews too...) PiperOrigin-RevId: 693353388 --- .../src/main/java/com/google/errorprone/util/ASTHelpers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java b/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java index 1491b4dbd81..0b762e849bb 100644 --- a/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java +++ b/check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java @@ -535,7 +535,7 @@ public static Type getReturnType(ExpressionTree expressionTree) { */ public static @Nullable Type getResultType(ExpressionTree expressionTree) { Type type = ASTHelpers.getType(expressionTree); - return type == null ? null : Optional.ofNullable(type.getReturnType()).orElse(type); + return type == null ? null : (type.getReturnType() == null ? type : type.getReturnType()); } /**