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

Replace argument with pre-sized array #2925

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public AbstractSerialStateHolder(final Object userBean,
this.userBean = userBean;
this.unloadedProperties = new HashMap<>(unloadedProperties);
this.objectFactory = objectFactory;
this.constructorArgTypes = constructorArgTypes.toArray(new Class<?>[0]);
this.constructorArgs = constructorArgs.toArray(new Object[0]);
this.constructorArgTypes = constructorArgTypes.toArray(new Class<?>[constructorArgTypes.size()]);
this.constructorArgs = constructorArgs.toArray(new Object[constructorArgs.size()]);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/ibatis/plugin/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static Class<?>[] getAllInterfaces(Class<?> type, Map<Class<?>, Set<Meth
}
type = type.getSuperclass();
}
return interfaces.toArray(new Class<?>[0]);
return interfaces.toArray(new Class<?>[interfaces.size()]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static boolean isSpecialParameter(Class<?> clazz) {
* @return the names
*/
public String[] getNames() {
return names.values().toArray(new String[0]);
return names.values().toArray(new String[names.size()]);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/apache/ibatis/reflection/Reflector.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public Reflector(Class<?> clazz) {
addSetMethods(classMethods);
addFields(clazz);
}
readablePropertyNames = getMethods.keySet().toArray(new String[0]);
writablePropertyNames = setMethods.keySet().toArray(new String[0]);
readablePropertyNames = getMethods.keySet().toArray(new String[getMethods.size()]);
writablePropertyNames = setMethods.keySet().toArray(new String[setMethods.size()]);
for (String propName : readablePropertyNames) {
caseInsensitivePropertyMap.put(propName.toUpperCase(Locale.ENGLISH), propName);
}
Expand Down Expand Up @@ -303,7 +303,7 @@ private Method[] getClassMethods(Class<?> clazz) {

Collection<Method> methods = uniqueMethods.values();

return methods.toArray(new Method[0]);
return methods.toArray(new Method[methods.size()]);
}

private void addUniqueMethods(Map<String, Method> uniqueMethods, Method[] methods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ private <T> T instantiateClass(Class<T> type, List<Class<?>> constructorArgTypes
throw e;
}
}
constructor = type.getDeclaredConstructor(constructorArgTypes.toArray(new Class[0]));
constructor = type.getDeclaredConstructor(constructorArgTypes.toArray(new Class[constructorArgTypes.size()]));
try {
return constructor.newInstance(constructorArgs.toArray(new Object[0]));
return constructor.newInstance(constructorArgs.toArray(new Object[constructorArgs.size()]));
} catch (IllegalAccessException e) {
if (Reflector.canControlMemberAccessible()) {
constructor.setAccessible(true);
return constructor.newInstance(constructorArgs.toArray(new Object[0]));
return constructor.newInstance(constructorArgs.toArray(new Object[constructorArgs.size()]));
}
throw e;
}
Expand Down