util
util copied to clipboard
util-varexport: only traverse methods once
Copied from an Indeed internal improvement request:
VarExporter.export traverses and exports @Export-annotated methods more than once in some scenarios. Make it stop doing that.
In particular, this code collects a set of all superinterfaces and calls getMethods on each of them (if declaredFieldsOnly is false). That results in O(NumberOfInterfaces) export attempts per method in the worst case:
Set<Class<?>> classAndInterfaces = Sets.newHashSet();
getAllInterfaces(c, classAndInterfaces);
classAndInterfaces.add(c);
for (Class<?> cls : classAndInterfaces) {
for (final Method method : (declaredFieldsOnly ? cls.getDeclaredMethods() : cls.getMethods())) {
Export export = method.getAnnotation(Export.class);
if (Modifier.isStatic(method.getModifiers())) {
loadMemberVariable(method, export, c, true, prefix, null);
} else {
loadMemberVariable(method, export, obj, true, prefix, null);
}
}
}