Speed up sorting of members
We put "!" in front of the names of members, then while sorting we simply chop off the part of the string before "!"
This commit is contained in:
@@ -42,7 +42,6 @@ import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
@@ -73,7 +72,10 @@ public class NamespaceComparator {
|
||||
@NotNull Predicate<NamespaceDescriptor> includeIntoOutput,
|
||||
@NotNull File txtFile
|
||||
) {
|
||||
String serialized = assertNamespacesEqual(nsa, nsb, includeObject, includeIntoOutput);
|
||||
String serializedFormWithDemarkedNames = assertNamespacesEqual(nsa, nsb, includeObject, includeIntoOutput);
|
||||
// The serializer puts "!" in front of the name because it allows for speedy sorting of members
|
||||
// see MemberComparator.normalize()
|
||||
String serialized = serializedFormWithDemarkedNames.replace("!", "");
|
||||
try {
|
||||
if (!txtFile.exists()) {
|
||||
FileUtil.writeToFile(txtFile, serialized);
|
||||
@@ -204,12 +206,15 @@ public class NamespaceComparator {
|
||||
*/
|
||||
private static class MemberComparator implements Comparator<String> {
|
||||
|
||||
private static final Pattern IRRELEVANT = Pattern.compile(
|
||||
"^ *(private|protected|public|internal|final|abstract|open|override|fun|val|var|/\\*.*?\\*/|((?!<init>)<.*?>)| )*");
|
||||
|
||||
@NotNull
|
||||
private String normalize(String s) {
|
||||
return IRRELEVANT.matcher(s).replaceAll("");
|
||||
// Serializers put "!" in front of the name in order to facilitate faster sorting of members
|
||||
int i = s.indexOf("!");
|
||||
if (i < 0) {
|
||||
throw new IllegalStateException("No name mark in " + s);
|
||||
}
|
||||
String substring = s.substring(i + 1);
|
||||
return substring;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -345,7 +350,6 @@ public class NamespaceComparator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void serialize(FunctionDescriptor fun) {
|
||||
serialize(fun.getVisibility());
|
||||
sb.append(" ");
|
||||
@@ -371,12 +375,10 @@ public class NamespaceComparator {
|
||||
sb.append(">");
|
||||
}
|
||||
|
||||
if (fun.getReceiverParameter().exists()) {
|
||||
new TypeSerializer(sb).serialize(fun.getReceiverParameter());
|
||||
sb.append(".");
|
||||
}
|
||||
|
||||
sb.append("!");
|
||||
serializeReceiver(fun);
|
||||
sb.append(fun.getName());
|
||||
|
||||
sb.append("(");
|
||||
new TypeSerializer(sb).serializeCommaSeparated(fun.getValueParameters());
|
||||
sb.append("): ");
|
||||
@@ -389,6 +391,13 @@ public class NamespaceComparator {
|
||||
}
|
||||
}
|
||||
|
||||
private void serializeReceiver(CallableDescriptor fun) {
|
||||
if (fun.getReceiverParameter().exists()) {
|
||||
new TypeSerializer(sb).serialize(fun.getReceiverParameter());
|
||||
sb.append(".");
|
||||
}
|
||||
}
|
||||
|
||||
public void serialize(ExtensionReceiver extensionReceiver) {
|
||||
serialize(extensionReceiver.getType());
|
||||
}
|
||||
@@ -437,6 +446,7 @@ public class NamespaceComparator {
|
||||
new Serializer(sb).serializeCommaSeparated(prop.getTypeParameters());
|
||||
sb.append("> ");
|
||||
}
|
||||
sb.append("!");
|
||||
if (prop.getReceiverParameter().exists()) {
|
||||
new TypeSerializer(sb).serialize(prop.getReceiverParameter().getType());
|
||||
sb.append(".");
|
||||
@@ -457,6 +467,7 @@ public class NamespaceComparator {
|
||||
if (valueParameter.getVarargElementType() != null) {
|
||||
sb.append("vararg ");
|
||||
}
|
||||
sb.append("!");
|
||||
sb.append(valueParameter.getName());
|
||||
sb.append(": ");
|
||||
if (valueParameter.getVarargElementType() != null) {
|
||||
@@ -662,6 +673,7 @@ public class NamespaceComparator {
|
||||
serialize(klass.getKind());
|
||||
sb.append(" ");
|
||||
|
||||
sb.append("!");
|
||||
new Serializer(sb).serialize(klass);
|
||||
|
||||
if (!klass.getTypeConstructor().getParameters().isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user