From a47424eafeb8a14bdeb6b2216c0b0e5f56200d8f Mon Sep 17 00:00:00 2001 From: Rajesh Balamohan Date: Wed, 21 Feb 2018 06:15:19 +1100 Subject: [PATCH] Consider improving LDUser::getValueForEvaluation performance for custom attributes --- src/main/java/com/launchdarkly/client/LDUser.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/launchdarkly/client/LDUser.java b/src/main/java/com/launchdarkly/client/LDUser.java index 95209dc90..a36025f2d 100644 --- a/src/main/java/com/launchdarkly/client/LDUser.java +++ b/src/main/java/com/launchdarkly/client/LDUser.java @@ -71,10 +71,14 @@ public LDUser(String key) { } protected JsonElement getValueForEvaluation(String attribute) { + JsonElement returnVal = getCustom(attribute); + if (returnVal != null) { + return returnVal; + } try { return UserAttribute.valueOf(attribute).get(this); } catch (IllegalArgumentException expected) { - return getCustom(attribute); + return null; } } @@ -127,7 +131,7 @@ JsonPrimitive getAnonymous() { } JsonElement getCustom(String key) { - if (custom != null) { + if (custom != null && !custom.isEmpty()) { return custom.get(key); } return null;