mirror of
https://gitee.com/arthas/arthas.git
synced 2024-11-29 18:58:37 +08:00
Optimize toArray (#484)
replace toArray(new T[size]) with toArray(new T[0]) for better performance https://shipilev.net/blog/2016/arrays-wisdom-ancients/#_conclusion
This commit is contained in:
parent
efb835823e
commit
4dba865995
@ -129,7 +129,7 @@ public class ThreadCommand extends AnnotatedCommand {
|
||||
|
||||
private void processTopBusyThreads(CommandProcess process) {
|
||||
Map<Long, Long> topNThreads = ThreadUtil.getTopNThreads(sampleInterval, topNBusy);
|
||||
Long[] tids = topNThreads.keySet().toArray(new Long[topNThreads.keySet().size()]);
|
||||
Long[] tids = topNThreads.keySet().toArray(new Long[0]);
|
||||
ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(ArrayUtils.toPrimitive(tids), true, true);
|
||||
if (threadInfos == null) {
|
||||
process.write("thread do not exist! id: " + id + "\n");
|
||||
|
@ -236,7 +236,7 @@ public class FeatureCodec {
|
||||
|
||||
}
|
||||
|
||||
return segmentArrayList.toArray(new String[segmentArrayList.size()]);
|
||||
return segmentArrayList.toArray(new String[0]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -538,7 +538,7 @@ public abstract class StringUtils {
|
||||
|
||||
|
||||
public static String[] toStringArray(Collection<String> collection) {
|
||||
return collection == null?null:(String[])collection.toArray(new String[collection.size()]);
|
||||
return collection == null?null:(String[])collection.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public static String[] split(String toSplit, String delimiter) {
|
||||
|
@ -160,6 +160,6 @@ public class TypeRenderUtils {
|
||||
types.add(annotation.annotationType());
|
||||
}
|
||||
}
|
||||
return StringUtils.concat(",", types.toArray(new Class<?>[types.size()]));
|
||||
return StringUtils.concat(",", types.toArray(new Class<?>[0]));
|
||||
}
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ public class FieldUtils {
|
||||
*/
|
||||
public static Field[] getAllFields(final Class<?> cls) {
|
||||
final List<Field> allFieldsList = getAllFieldsList(cls);
|
||||
return allFieldsList.toArray(new Field[allFieldsList.size()]);
|
||||
return allFieldsList.toArray(new Field[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user