perf[stream]: stream.toList() replaces collect(Collectors.toList())

This commit is contained in:
sun
2023-09-12 13:58:46 +08:00
parent ac2d01e6fb
commit ad7e4f3481
17 changed files with 29 additions and 29 deletions
@@ -84,7 +84,7 @@ public abstract class GenerateProtocolFile {
var outsideGenerateProtocols = Arrays.stream(protocols)
.filter(it -> Objects.nonNull(it))
.filter(it -> generateProtocolFilter.test(it))
.toList();;
.toList();
// 需要生成的子协议,因为外层协议的内部有其它协议
var insideGenerateProtocols = outsideGenerateProtocols.stream()
@@ -92,7 +92,7 @@ public abstract class GenerateProtocolFile {
.flatMap(it -> it.stream())
.map(it -> protocols[it])
.distinct()
.toList();;
.toList();
var allGenerateProtocols = new HashSet<IProtocolRegistration>();
allGenerateProtocols.addAll(outsideGenerateProtocols);
@@ -101,7 +101,7 @@ public abstract class GenerateProtocolFile {
// 通过协议号,从小到大排序
var allSortedGenerateProtocols = allGenerateProtocols.stream()
.sorted((a, b) -> a.protocolId() - b.protocolId())
.toList();;
.toList();
// 解析协议的文档注释
GenerateProtocolNote.initProtocolNote(allSortedGenerateProtocols);
@@ -116,7 +116,7 @@ public abstract class GenerateProtocolPath {
for (var i = splits.length; i > 0; i--) {
builder.append("../");
var path = StringUtils.joinWith(StringUtils.PERIOD, Arrays.stream(splits).limit(i).toList();.toArray());
var path = StringUtils.joinWith(StringUtils.PERIOD, Arrays.stream(splits).limit(i).toList().toArray());
if (relativePath.startsWith(path)) {
builder.append(StringUtils.substringAfterFirst(relativePath, path).replaceAll(StringUtils.PERIOD_REGEX, StringUtils.SLASH));
return builder.toString();
@@ -180,7 +180,7 @@ public abstract class GenerateProtocolPath {
var allChildren = protocolTreeNode.flatTreeNodes()
.stream()
.filter(it -> it.getData() != null)
.toList();;
.toList();
var pathBefore = StringUtils.substringBeforeLast(protocolTreeNode.fullName(), StringUtils.PERIOD);
for (var child : allChildren) {
var protocolSimpleName = child.getData().protocolConstructor().getDeclaringClass().getSimpleName();
@@ -126,7 +126,7 @@ public abstract class EnhanceUtils {
var allSubProtocolIds = ProtocolAnalysis.getAllSubProtocolIds(protocolId)
.stream()
.sorted((a, b) -> Short.compare(a, b))
.toList();;
.toList();
for (var subProtocolId : allSubProtocolIds) {
var protocolRegistrationField = new CtField(classPool.get(IProtocolRegistration.class.getCanonicalName()), getProtocolRegistrationFieldNameByProtocolId(subProtocolId), enhanceClazz);
@@ -107,7 +107,7 @@ public class ProtocolAnalysis {
}
// 通过指定类注册的协议,全部使用字节码增强
var enhanceList = Arrays.stream(protocols).filter(Objects::nonNull).toList();;
var enhanceList = Arrays.stream(protocols).filter(Objects::nonNull).toList();
enhance(generateOperation, enhanceList);
}
@@ -121,7 +121,7 @@ public class ProtocolAnalysis {
var relevantClassList = relevantClassSet.stream()
.sorted((a, b) -> a.getCanonicalName().compareTo(b.getCanonicalName()))
.toList();;
.toList();
// 检查协议类是否合法
var noProtocolIds = new ArrayList<Class<?>>();
@@ -148,7 +148,7 @@ public class ProtocolAnalysis {
}
// 通过指定类注册的协议,全部使用字节码增强
var enhanceList = Arrays.stream(protocols).filter(Objects::nonNull).toList();;
var enhanceList = Arrays.stream(protocols).filter(Objects::nonNull).toList();
enhance(generateOperation, enhanceList);
}
@@ -414,7 +414,7 @@ public class ProtocolAnalysis {
.stream()
.sorted((a, b) -> a.getKey() - b.getKey())
.map(Map.Entry::getValue)
.toList();;
.toList();
notCompatibleFields.addAll(compatibleFields);
return notCompatibleFields;
}
@@ -210,7 +210,7 @@ public abstract class GenerateCppUtils {
// ValueOf()方法
var valueOfParams = filedList.stream()
.map(it -> StringUtils.format("{} {}", it.getKey(), it.getValue()))
.toList();;
.toList();
var valueOfParamsStr = StringUtils.joinWith(StringUtils.COMMA + " ", valueOfParams.toArray());
var cppBuilder = new StringBuilder();
@@ -132,7 +132,7 @@ public abstract class GenerateJsUtils {
var protocolId = registration.getId();
var fields = registration.getFields();
var fieldValueOf = StringUtils.joinWith(", ", Arrays.stream(fields).map(it -> it.getName()).toList();.toArray());
var fieldValueOf = StringUtils.joinWith(", ", Arrays.stream(fields).map(it -> it.getName()).toList().toArray());
var fieldDefinitionBuilder = new StringBuilder();
for (var field : fields) {
@@ -135,7 +135,7 @@ public abstract class GenerateLuaUtils {
var protocolId = registration.getId();
var fields = registration.getFields();
var valueOfParams = StringUtils.joinWith(", ", Arrays.stream(fields).map(it -> it.getName()).toList();.toArray());
var valueOfParams = StringUtils.joinWith(", ", Arrays.stream(fields).map(it -> it.getName()).toList().toArray());
var luaBuilder = new StringBuilder();
for (var i = 0; i < fields.length; i++) {
@@ -318,7 +318,7 @@ public abstract class ReflectionUtils {
.filter(it -> !Modifier.isStatic(it.getModifiers()))
.filter(it -> !Modifier.isTransient(it.getModifiers()))
.filter(it -> !it.isAnnotationPresent(Transient.class))
.toList();;
.toList();
}
public static String fieldToGetMethod(Class<?> clazz, Field field) {