From 8d075ce39d71ed881969e1a2cf00abe7f5b546b7 Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Tue, 10 Jan 2017 23:46:09 +0100 Subject: Use a method cache in front of the "deconstruct" method lookup --- .../java/com/yahoo/component/AbstractComponent.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'component/src') diff --git a/component/src/main/java/com/yahoo/component/AbstractComponent.java b/component/src/main/java/com/yahoo/component/AbstractComponent.java index 2fe11425d20..7e4eb665278 100644 --- a/component/src/main/java/com/yahoo/component/AbstractComponent.java +++ b/component/src/main/java/com/yahoo/component/AbstractComponent.java @@ -1,6 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.component; +import com.yahoo.collections.MethodCache; + import java.lang.reflect.Method; /** @@ -11,6 +13,8 @@ import java.lang.reflect.Method; */ public class AbstractComponent implements Component { + static final MethodCache deconstructMethods = new MethodCache("deconstruct"); + // All accesses to id MUST go through getId. private ComponentId id; @@ -129,16 +133,12 @@ public class AbstractComponent implements Component { } protected boolean setIsDeconstructable() { - try { - Method deconstruct = getClass().getMethod("deconstruct"); - @SuppressWarnings("rawtypes") - Class declaringClass = deconstruct.getDeclaringClass(); - if (declaringClass != AbstractComponent.class) { - return true; - } - } catch (NoSuchMethodException e) { + Method deconstruct = deconstructMethods.get(this); + if (deconstruct == null) { com.yahoo.protect.Process.logAndDie("Component " + this + " does not have method deconstruct() - impossible!"); } - return false; + @SuppressWarnings("rawtypes") + Class declaringClass = deconstruct.getDeclaringClass(); + return (declaringClass != AbstractComponent.class); } } -- cgit v1.2.3