Skip to content

Commit 18c267f

Browse files
committed
Share TruffleString.EqualNode used in specialization guard.
(cherry picked from commit f2de9b3)
1 parent 48beb74 commit 18c267f

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/CompileRegexNode.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -55,11 +55,12 @@
5555
import com.oracle.truffle.js.runtime.RegexCompilerInterface;
5656
import com.oracle.truffle.js.runtime.Strings;
5757

58-
@ImportStatic(JSConfig.class)
58+
@ImportStatic({JSConfig.class, Strings.class})
5959
public 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

Comments
 (0)