4040 */
4141package com .oracle .graal .python .builtins .objects .str ;
4242
43+ import org .graalvm .nativeimage .ImageInfo ;
44+
4345import com .oracle .graal .python .nodes .PGuards ;
4446import com .oracle .graal .python .runtime .PythonOptions ;
4547import 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