GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #291 from jbgi/fix-groupby-perf · lovejavaee/functionaljava@353507b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • core/src/main/java/fj/data
    • List.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎core/src/main/java/fj/data/List.java‎

Copy file name to clipboardExpand all lines: core/src/main/java/fj/data/List.java
+9-8Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,14 +1398,15 @@ public final <B, C, D> TreeMap<B, D> groupBy(
13981398
final D groupingIdentity,
13991399
final F2<C, D, D> groupingAcc,
14001400
final Ord<B> keyOrd) {
1401-
return this.foldLeft((map, element) -> {
1402-
final B key = keyFunction.f(element);
1403-
final C value = valueFunction.f(element);
1404-
return map.set(key, map.get(key)
1405-
.map(existing -> groupingAcc.f(value, existing))
1406-
.orSome(groupingAcc.f(value, groupingIdentity)));
1407-
}, TreeMap.empty(keyOrd)
1408-
);
1401+
java.util.TreeMap<B, D> buffer = new java.util.TreeMap<>(keyOrd.toComparator());
1402+
foreachDoEffect(element -> {
1403+
final B key = keyFunction.f(element);
1404+
final C value = valueFunction.f(element);
1405+
buffer.put(key, buffer.containsKey(key)
1406+
? groupingAcc.f(value, buffer.get(key))
1407+
: groupingAcc.f(value, groupingIdentity));
1408+
});
1409+
return TreeMap.fromMutableMap(keyOrd, buffer);
14091410
}
14101411

14111412

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.