Skip to content

Commit d4ab025

Browse files
committed
LENGTH_TABLE must be CompilationFinal for 14.to_s.length to fold to a PE constant
* Tested in PE tests.
1 parent 34d4436 commit d4ab025

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/java/org/truffleruby/core/rope/LazyIntRope.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.truffleruby.core.rope;
1111

1212
import com.oracle.truffle.api.CompilerDirectives;
13+
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
1314
import com.oracle.truffle.api.profiles.ConditionProfile;
1415
import org.jcodings.Encoding;
1516
import org.jcodings.specific.USASCIIEncoding;
@@ -30,7 +31,7 @@ protected LazyIntRope(int value, Encoding encoding, int length) {
3031
assert Integer.toString(value).length() == length : value + " " + length;
3132
}
3233

33-
private static final int[] LENGTH_TABLE = {
34+
@CompilationFinal(dimensions = 1) private static final int[] LENGTH_TABLE = {
3435
9,
3536
99,
3637
999,
@@ -42,7 +43,8 @@ protected LazyIntRope(int value, Encoding encoding, int length) {
4243
999999999,
4344
Integer.MAX_VALUE };
4445

45-
// From https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/master/2021/05/28/digitcount.java
46+
// From https://lemire.me/blog/2021/05/28/computing-the-number-of-digits-of-an-integer-quickly/
47+
// and https://github.com/lemire/Code-used-on-Daniel-Lemire-s-blog/blob/9d4cd21d0a/2021/05/28/digitcount.java (license: public domain)
4648
private static int length(int value) {
4749
final int sign;
4850
if (CompilerDirectives.injectBranchProbability(CompilerDirectives.UNLIKELY_PROBABILITY, value < 0)) {

0 commit comments

Comments
 (0)