This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.IntSupplier; | |
import java.util.stream.IntStream; | |
public class Benchmark { | |
private int compute() { | |
IntSupplier s1 = () -> IntStream.range(0, 10000).map(v -> 1).sum(); | |
IntSupplier s2 = () -> IntStream.range(0, 10000).map(v -> 1).sum(); | |
IntSupplier s3 = () -> IntStream.range(0, 10000).map(v -> 1).sum(); | |
return s1.getAsInt() + s2.getAsInt() + s3.getAsInt(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: src/java.base/share/classes/java/lang/AbstractStringBuilder.java | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
diff --git a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java | |
--- a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java (revision 674fa32cf8403ceec84bbe2c3f9404d612c10797) | |
+++ b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java (date 1674682743075) | |
@@ -1680,8 +1680,8 @@ | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class MemoryTest { | |
public static void main(String[] args) { | |
var processors = new ArrayList<Processor>(); | |
for (int i = 0; i < 1000; i++) { | |
int[] data = new int[10_000_000]; | |
processors.add(new Processor(data) { | |
@Override | |
int calculate() { |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import one.util.streamex.MoreCollectors; | |
import one.util.streamex.StreamEx; | |
import java.util.stream.Collector; | |
class Test { | |
enum MyLattice { | |
/* | |
TOP | |
/ \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java b/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java | |
--- a/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java (revision 57611b30219191160f7faccb811b41a31c25c0b8) | |
+++ b/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java (date 1626887157914) | |
@@ -315,6 +315,18 @@ | |
return generateInnerClass(); | |
} | |
+ private static StackTraceElement getCallerFrame() { | |
+ StackTraceElement[] trace = new Exception().getStackTrace(); | |
+ for (int i = 0; i < trace.length - 1; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Circle { | |
public static void main(String[] args) { | |
// Preparation | |
int radius = Integer.parseInt(args[0]); | |
int rasterSize = radius * 2 + 1; | |
boolean[][] raster = new boolean[rasterSize][rasterSize]; | |
// Bresenham algorithm | |
int y = radius; | |
int err = radius; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.util.stream.*; | |
public class StringBuilderInHashMap { | |
public static void main(String[] args) { | |
List<StringBuilder> list = Stream.generate(() -> { | |
while (true) { | |
StringBuilder sb = new StringBuilder("a"); | |
int hc = sb.hashCode(); | |
if (((hc ^ (hc >>> 16)) & 0x3F) == 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class BreakHashSet { | |
public static void main(String[] args) { | |
Point[] points = new Point[20]; | |
Arrays.setAll(points, idx -> new Point(idx * 500_000_000, | |
-new Point(idx * 500_000_000, 0).hashCode())); | |
Set<Point> set = new HashSet<>(Arrays.asList(points)); | |
set.remove(points[1]); | |
System.out.println(set.contains(points[14])); // Prints false! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Collection; | |
import java.util.Comparator; | |
import java.util.PriorityQueue; | |
import java.util.SortedSet; | |
import java.util.TreeSet; | |
import java.util.concurrent.PriorityBlockingQueue; | |
public class WhoInheritsComparator { | |
public static void main(String[] args) { | |
SortedSet<Integer> c1 = new TreeSet<>(Comparator.reverseOrder()); |
NewerOlder