Skip to content

Commit ec61042

Browse files
committed
[GR-15077] Rework the LazyString class initializer logic.
PullRequest: graalpython/483
2 parents d82ba53 + a63961b commit ec61042

File tree

1 file changed

+8
-13
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str

1 file changed

+8
-13
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/LazyString.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
*/
4141
package com.oracle.graal.python.builtins.objects.str;
4242

43+
import org.graalvm.nativeimage.ImageInfo;
44+
4345
import com.oracle.graal.python.nodes.PGuards;
4446
import com.oracle.graal.python.runtime.PythonOptions;
4547
import com.oracle.truffle.api.CompilerAsserts;
@@ -51,20 +53,13 @@ public class LazyString implements CharSequence {
5153
protected static final int MinLazyStringLength;
5254
protected static final boolean UseLazyStrings;
5355
static {
54-
boolean useLazyStrings;
55-
int minLazyStringLength;
56-
try {
57-
useLazyStrings = PythonOptions.useLazyString();
58-
minLazyStringLength = PythonOptions.getMinLazyStringLength();
59-
} catch (AssertionError e) {
60-
// This can happen e.g. when we build a native image without
61-
// a pre-initialized Python context
62-
assert e.getMessage().equals("No current context available");
63-
useLazyStrings = PythonOptions.LazyStrings.getDefaultValue();
64-
minLazyStringLength = PythonOptions.MinLazyStringLength.getDefaultValue();
56+
if (ImageInfo.inImageBuildtimeCode()) {
57+
MinLazyStringLength = PythonOptions.MinLazyStringLength.getDefaultValue();
58+
UseLazyStrings = PythonOptions.LazyStrings.getDefaultValue();
59+
} else {
60+
MinLazyStringLength = PythonOptions.getMinLazyStringLength();
61+
UseLazyStrings = PythonOptions.useLazyString();
6562
}
66-
MinLazyStringLength = minLazyStringLength;
67-
UseLazyStrings = useLazyStrings;
6863
}
6964

7065
public static int length(CharSequence cs, ConditionProfile profile1, ConditionProfile profile2) {

0 commit comments

Comments
 (0)