-
Enhancement
-
Resolution: Fixed
-
P4
-
None
-
None
For a single-element set, Set.of uses Set12 with the second element set to null. For determining @Stableness, a null value is a proxy for "might not be initialized", which unfortunately means the JIT can't consistently constant fold operations that check e1 == null.
Since null values are prohibited, and a 2-element Set disallows duplicate entries, we could get around this by storing the same instance to both fields of Set12 in the single-element constructor. This allows operations like set.size() to be properly constant folded, with a modest improvement in targeted microbenchmarks.
Since null values are prohibited, and a 2-element Set disallows duplicate entries, we could get around this by storing the same instance to both fields of Set12 in the single-element constructor. This allows operations like set.size() to be properly constant folded, with a modest improvement in targeted microbenchmarks.