Skip to content

Commit f96504a

Browse files
committed
Simplify
1 parent f50b8da commit f96504a

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

src/main/java/org/truffleruby/core/hash/FreezeHashKeyIfNeededNode.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,49 @@
99
*/
1010
package org.truffleruby.core.hash;
1111

12+
import com.oracle.truffle.api.dsl.Cached;
1213
import org.truffleruby.core.string.RubyString;
1314
import org.truffleruby.language.ImmutableRubyString;
1415
import org.truffleruby.language.RubyContextNode;
1516
import org.truffleruby.language.dispatch.DispatchNode;
1617
import org.truffleruby.language.library.RubyLibrary;
1718

18-
import com.oracle.truffle.api.CompilerDirectives;
1919
import com.oracle.truffle.api.dsl.Specialization;
2020
import com.oracle.truffle.api.library.CachedLibrary;
21-
import org.truffleruby.language.library.RubyStringLibrary;
2221

2322
public abstract class FreezeHashKeyIfNeededNode extends RubyContextNode {
2423

25-
@Child private DispatchNode dupNode;
26-
2724
public abstract Object executeFreezeIfNeeded(Object key, boolean compareByIdentity);
2825

2926
@Specialization
30-
protected Object alreadyFrozen(ImmutableRubyString string, boolean compareByIdentity) {
27+
protected Object immutable(ImmutableRubyString string, boolean compareByIdentity) {
3128
return string;
3229
}
3330

3431
@Specialization(
35-
guards = { "strings.isRubyString(string)", "rubyLibrary.isFrozen(string)" },
32+
guards = "rubyLibrary.isFrozen(string)",
3633
limit = "getRubyLibraryCacheLimit()")
37-
protected Object alreadyFrozen(Object string, boolean compareByIdentity,
38-
@CachedLibrary(limit = "2") RubyStringLibrary strings,
34+
protected Object alreadyFrozen(RubyString string, boolean compareByIdentity,
3935
@CachedLibrary("string") RubyLibrary rubyLibrary) {
4036
return string;
4137
}
4238

4339
@Specialization(
44-
guards = { "strings.isRubyString(string)", "!rubyLibrary.isFrozen(string)", "!compareByIdentity" },
40+
guards = { "!rubyLibrary.isFrozen(string)", "!compareByIdentity" },
4541
limit = "getRubyLibraryCacheLimit()")
46-
protected Object dupAndFreeze(Object string, boolean compareByIdentity,
47-
@CachedLibrary(limit = "2") RubyStringLibrary strings,
42+
protected Object dupAndFreeze(RubyString string, boolean compareByIdentity,
4843
@CachedLibrary("string") RubyLibrary rubyLibrary,
49-
@CachedLibrary(limit = "getRubyLibraryCacheLimit()") RubyLibrary rubyLibraryObject) {
50-
final Object object = dup(string);
44+
@CachedLibrary(limit = "getRubyLibraryCacheLimit()") RubyLibrary rubyLibraryObject,
45+
@Cached DispatchNode dupNode) {
46+
final Object object = dupNode.call(string, "dup");
5147
rubyLibraryObject.freeze(object);
5248
return object;
5349
}
5450

5551
@Specialization(
56-
guards = { "strings.isRubyString(string)", "!rubyLibrary.isFrozen(string)", "compareByIdentity" },
52+
guards = { "!rubyLibrary.isFrozen(string)", "compareByIdentity" },
5753
limit = "getRubyLibraryCacheLimit()")
5854
protected Object compareByIdentity(RubyString string, boolean compareByIdentity,
59-
@CachedLibrary(limit = "2") RubyStringLibrary strings,
6055
@CachedLibrary("string") RubyLibrary rubyLibrary) {
6156
return string;
6257
}
@@ -66,14 +61,4 @@ protected Object passThrough(Object value, boolean compareByIdentity) {
6661
return value;
6762
}
6863

69-
70-
private Object dup(Object value) {
71-
if (dupNode == null) {
72-
CompilerDirectives.transferToInterpreterAndInvalidate();
73-
dupNode = insert(DispatchNode.create());
74-
}
75-
return dupNode.call(value, "dup");
76-
}
77-
78-
7964
}

0 commit comments

Comments
 (0)