use of it.unimi.dsi.fastutil.ints.IntSet in project gradle by gradle.
the class ClassSetAnalysisData method reduceToTypesAffecting.
/**
* Returns a shrunk down version of this class set, which only contains information about types that could affect the other set.
* This is useful for reducing the size of classpath snapshots, since a classpath usually contains a lot more types than the client
* actually uses.
*
* Apart from the obvious classes that are directly used by the other set, we also need to keep any classes that might affect any number
* of classes, like package-info, module-info and inlineable constants.
*/
public ClassSetAnalysisData reduceToTypesAffecting(ClassSetAnalysisData other, CompilerApiData compilerApiData) {
if (fullRebuildCause != null) {
return this;
}
Set<String> usedClasses = new HashSet<>(classHashes.size());
for (Map.Entry<String, DependentsSet> entry : dependents.entrySet()) {
if (entry.getValue().isDependencyToAll()) {
usedClasses.add(entry.getKey());
}
}
for (String cls : classHashes.keySet()) {
if (cls.endsWith(PACKAGE_INFO)) {
usedClasses.add(cls);
}
}
usedClasses.addAll(other.dependents.keySet());
Multimap<String, String> dependencies = getForwardDependencyView();
Set<String> visited = new HashSet<>(usedClasses.size());
Deque<String> pending = new ArrayDeque<>(usedClasses);
while (!pending.isEmpty()) {
String cls = pending.poll();
if (visited.add(cls)) {
usedClasses.add(cls);
pending.addAll(dependencies.get(cls));
}
}
Set<String> usedConstantSources = compilerApiData.isSupportsConstantsMapping() ? compilerApiData.getConstantToClassMapping().getConstantDependents().keySet() : classesToConstants.keySet();
usedClasses.addAll(usedConstantSources);
Map<String, HashCode> classHashes = new HashMap<>(usedClasses.size());
Map<String, DependentsSet> dependents = new HashMap<>(usedClasses.size());
Map<String, IntSet> classesToConstants = new HashMap<>(usedClasses.size());
for (String usedClass : usedClasses) {
HashCode hash = this.classHashes.get(usedClass);
if (hash != null) {
classHashes.put(usedClass, hash);
DependentsSet dependentsSet = this.dependents.get(usedClass);
if (dependentsSet != null) {
if (dependentsSet.isDependencyToAll()) {
dependents.put(usedClass, dependentsSet);
} else {
Set<String> usedAccessibleClasses = new HashSet<>(dependentsSet.getAccessibleDependentClasses());
usedAccessibleClasses.retainAll(usedClasses);
if (!usedAccessibleClasses.isEmpty()) {
dependents.put(usedClass, DependentsSet.dependentClasses(Collections.emptySet(), usedAccessibleClasses));
}
}
}
IntSet constants = this.classesToConstants.get(usedClass);
if (constants != null && usedConstantSources.contains(usedClass)) {
classesToConstants.put(usedClass, constants);
}
}
}
return new ClassSetAnalysisData(classHashes, dependents, classesToConstants, null);
}
use of it.unimi.dsi.fastutil.ints.IntSet in project gradle by gradle.
the class ClassAnalysisSerializer method read.
@Override
public ClassAnalysis read(Decoder decoder) throws Exception {
String className = decoder.readString();
boolean relatedToAll = decoder.readBoolean();
Set<String> classes = STRING_SET_SERIALIZER.read(decoder);
IntSet constants = IntSetSerializer.INSTANCE.read(decoder);
Set<String> superTypes = STRING_SET_SERIALIZER.read(decoder);
return new ClassAnalysis(className, classes, relatedToAll, constants, superTypes);
}
use of it.unimi.dsi.fastutil.ints.IntSet in project gradle by gradle.
the class ClassDependenciesVisitor method analyze.
public static ClassAnalysis analyze(String className, ClassReader reader) {
IntSet constants = new IntOpenHashSet(2);
Set<String> classDependencies = Sets.newHashSet();
ClassDependenciesVisitor visitor = new ClassDependenciesVisitor(constants, classDependencies, new ClassRelevancyFilter(className), reader);
reader.accept(visitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
return new ClassAnalysis(className, classDependencies, visitor.isDependencyToAll(), constants, visitor.getSuperTypes());
}
use of it.unimi.dsi.fastutil.ints.IntSet in project gradle by gradle.
the class JarSnapshot method getRelevantConstants.
public IntSet getRelevantConstants(JarSnapshot other, Set<String> affectedClasses) {
IntSet result = new IntOpenHashSet();
for (String affectedClass : affectedClasses) {
IntSet difference = new IntOpenHashSet(other.getData().data.getConstants(affectedClass));
difference.removeAll(data.data.getConstants(affectedClass));
result.addAll(difference);
}
return result;
}
use of it.unimi.dsi.fastutil.ints.IntSet in project gradle by gradle.
the class PreviousCompilation method getDependents.
public DependentsSet getDependents(String className, IntSet newConstants) {
IntSet constants = new IntOpenHashSet(analysis.getData().getConstants(className));
constants.removeAll(newConstants);
return analysis.getRelevantDependents(className, constants);
}
Aggregations