Skip to content

Commit

Permalink
Refactor to use fewer streams and iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Apr 22, 2024
1 parent cf1935b commit e736637
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions core/src/main/java/org/jruby/anno/AnnotationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -103,15 +104,20 @@ public static void groupFrameFields(Map<Set<FrameField>, List<String>> readGroup

public static void populateMethodIndex(Map<Set<FrameField>, List<String>> accessGroups, BiConsumer<Integer, String> action) {
if (!accessGroups.isEmpty()) {
for (Map.Entry<Set<FrameField>, List<String>> accessEntry : accessGroups.entrySet()) {
Set<FrameField> reads = accessEntry.getKey();
List<String> names = accessEntry.getValue();

accessGroups.forEach((reads, names) -> {
int bits = FrameField.pack(reads.stream().toArray(n -> new FrameField[n]));
String namesJoined = names.stream().distinct().collect(Collectors.joining(";"));

StringJoiner joiner = new StringJoiner(";");
Set<String> uniqueValues = new HashSet<>();
for (String name : names) {
if (uniqueValues.add(name)) {
joiner.add(name);
}
}
String namesJoined = joiner.toString();

action.accept(bits, namesJoined);
}
});
}
}

Expand Down

0 comments on commit e736637

Please sign in to comment.