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

Optimise generated reflective calls #66

Open
dvojtise opened this issue Sep 19, 2018 · 1 comment
Open

Optimise generated reflective calls #66

dvojtise opened this issue Sep 19, 2018 · 1 comment

Comments

@dvojtise
Copy link
Contributor

in order to make sure that an attribute on emf side is used instead of the local variable in xtend, k3 generates some reflective calls.
ex for an Integer variable named "currentValue:

protected static Integer _privk3_currentValue(final VariableAspectVariableAspectProperties _self_, final Variable _self) {
    try {
    	for (java.lang.reflect.Method m : _self.getClass().getMethods()) {
    		if (m.getName().equals("getCurrentValue") &&
    			m.getParameterTypes().length == 0) {
    				Object ret = m.invoke(_self);
    				if (ret != null) {
    					return (java.lang.Integer) ret;
    				} else {
    					return null;
    				}
    		}
    	}
    } catch (Exception e) {
    	// Chut !
    }
    return _self_.currentValue;
  }
protected static void _privk3_currentValue(final VariableAspectVariableAspectProperties _self_, final Variable _self, final Integer currentValue) {
    boolean setterCalled = false;
    try {
    	for (java.lang.reflect.Method m : _self.getClass().getMethods()) {
    		if (m.getName().equals("setCurrentValue")
    				&& m.getParameterTypes().length == 1) {
    			m.invoke(_self, currentValue);
    			setterCalled = true;
    		}
    	}
    } catch (Exception e) {
    	// Chut !
    }
    if (!setterCalled) {
    	_self_.currentValue = currentValue;
    }
  }
}

they could benefit from the following study in order to use a more efficient coding of the reflective call: https://dzone.com/articles/java-reflection-but-faster?edition=398191&utm_source=Daily%20Digest&utm_medium=email&utm_campaign=Daily%20Digest%202018-09-18

@dvojtise
Copy link
Contributor Author

in addition the setter code currently loops over the whole set of methods and does not break the for loop...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant