11/*
2- * Copyright (c) 2018, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * The Universal Permissive License (UPL), Version 1.0
5555import com .oracle .truffle .js .runtime .RegexCompilerInterface ;
5656import com .oracle .truffle .js .runtime .Strings ;
5757
58- @ ImportStatic (JSConfig .class )
58+ @ ImportStatic ({ JSConfig .class , Strings . class } )
5959public abstract class CompileRegexNode extends JavaScriptBaseNode {
6060
6161 private final JSContext context ;
6262 @ Child private InteropLibrary isCompiledRegexNullNode ;
63+ @ Child TruffleString .EqualNode equalsNode = TruffleString .EqualNode .create ();
6364
6465 protected CompileRegexNode (JSContext context ) {
6566 this .context = context ;
@@ -81,13 +82,11 @@ public final Object compile(Object pattern, Object flags) {
8182 protected abstract Object executeCompile (Object pattern , Object flags );
8283
8384 @ SuppressWarnings ("unused" )
84- @ Specialization (guards = {"stringEquals (equalsNode, pattern, cachedPattern)" , "stringEquals(equalsNode2 , flags, cachedFlags)" }, limit = "MaxCompiledRegexCacheLength" )
85+ @ Specialization (guards = {"equals (equalsNode, pattern, cachedPattern)" , "equals(equalsNode , flags, cachedFlags)" }, limit = "MaxCompiledRegexCacheLength" )
8586 protected Object getCached (TruffleString pattern , TruffleString flags ,
8687 @ Cached ("pattern" ) TruffleString cachedPattern ,
8788 @ Cached ("flags" ) TruffleString cachedFlags ,
8889 @ Cached ("createAssumedValue()" ) AssumedValue <Object > cachedCompiledRegex ,
89- @ Cached TruffleString .EqualNode equalsNode ,
90- @ Cached TruffleString .EqualNode equalsNode2 ,
9190 @ Cached @ Shared TruffleString .ToJavaStringNode toJavaString ) {
9291 // Note: we must not compile the regex while holding the AST lock (initializing @Cached).
9392 Object cached = cachedCompiledRegex .get ();
@@ -98,10 +97,6 @@ protected Object getCached(TruffleString pattern, TruffleString flags,
9897 return cached ;
9998 }
10099
101- protected static boolean stringEquals (TruffleString .EqualNode node , TruffleString a , TruffleString b ) {
102- return Strings .equals (node , a , b );
103- }
104-
105100 @ Specialization (guards = {"!TrimCompiledRegexCache" })
106101 protected Object doCompileNoTrimCache (TruffleString pattern , TruffleString flags ,
107102 @ Cached @ Shared TruffleString .ToJavaStringNode toJavaString ) {
0 commit comments