Skip to content

Commit c1f33be

Browse files
committed
Avoid going through RubyLibrary for RubyString#{isFrozen,freeze}
* Saves footprint and indirections.
1 parent c3ac942 commit c1f33be

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

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

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
import org.truffleruby.core.string.ImmutableRubyString;
1616
import org.truffleruby.language.RubyBaseNode;
1717
import org.truffleruby.language.dispatch.DispatchNode;
18-
import org.truffleruby.language.library.RubyLibrary;
1918

2019
import com.oracle.truffle.api.dsl.Specialization;
21-
import com.oracle.truffle.api.library.CachedLibrary;
2220

2321
@GenerateUncached
2422
public abstract class FreezeHashKeyIfNeededNode extends RubyBaseNode {
@@ -30,31 +28,21 @@ protected Object immutable(ImmutableRubyString string, boolean compareByIdentity
3028
return string;
3129
}
3230

33-
@Specialization(
34-
guards = "rubyLibrary.isFrozen(string)",
35-
limit = "getRubyLibraryCacheLimit()")
36-
protected Object alreadyFrozen(RubyString string, boolean compareByIdentity,
37-
@CachedLibrary("string") RubyLibrary rubyLibrary) {
31+
@Specialization(guards = "string.isFrozen()")
32+
protected Object alreadyFrozen(RubyString string, boolean compareByIdentity) {
3833
return string;
3934
}
4035

41-
@Specialization(
42-
guards = { "!rubyLibrary.isFrozen(string)", "!compareByIdentity" },
43-
limit = "getRubyLibraryCacheLimit()")
36+
@Specialization(guards = { "!string.isFrozen()", "!compareByIdentity" })
4437
protected Object dupAndFreeze(RubyString string, boolean compareByIdentity,
45-
@CachedLibrary("string") RubyLibrary rubyLibrary,
46-
@CachedLibrary(limit = "getRubyLibraryCacheLimit()") RubyLibrary rubyLibraryObject,
4738
@Cached DispatchNode dupNode) {
48-
final Object object = dupNode.call(string, "dup");
49-
rubyLibraryObject.freeze(object);
50-
return object;
39+
final RubyString copy = (RubyString) dupNode.call(string, "dup");
40+
copy.freeze();
41+
return copy;
5142
}
5243

53-
@Specialization(
54-
guards = { "!rubyLibrary.isFrozen(string)", "compareByIdentity" },
55-
limit = "getRubyLibraryCacheLimit()")
56-
protected Object compareByIdentity(RubyString string, boolean compareByIdentity,
57-
@CachedLibrary("string") RubyLibrary rubyLibrary) {
44+
@Specialization(guards = { "!string.isFrozen()", "compareByIdentity" })
45+
protected Object compareByIdentity(RubyString string, boolean compareByIdentity) {
5846
return string;
5947
}
6048

src/main/java/org/truffleruby/core/string/RubyString.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ protected String getJavaString() {
9090

9191
// region RubyLibrary messages
9292
@ExportMessage
93-
protected void freeze() {
93+
public void freeze() {
9494
frozen = true;
9595
}
9696

9797
@ExportMessage
98-
protected boolean isFrozen() {
98+
public boolean isFrozen() {
9999
return frozen;
100100
}
101101
// endregion

0 commit comments

Comments
 (0)