Skip to content

Commit ff467bd

Browse files
committed
Use DynamicObjectLibrary SetClassVariableNode
1 parent 0195592 commit ff467bd

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

src/main/java/org/truffleruby/language/objects/classvariables/SetClassVariableNode.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99
*/
1010
package org.truffleruby.language.objects.classvariables;
1111

12-
import com.oracle.truffle.api.dsl.Cached;
1312
import com.oracle.truffle.api.dsl.NodeChild;
1413
import com.oracle.truffle.api.dsl.Specialization;
15-
import com.oracle.truffle.api.object.FinalLocationException;
16-
import com.oracle.truffle.api.object.IncompatibleLocationException;
17-
import com.oracle.truffle.api.object.Property;
18-
import com.oracle.truffle.api.object.Shape;
14+
import com.oracle.truffle.api.library.CachedLibrary;
15+
import com.oracle.truffle.api.object.DynamicObjectLibrary;
1916
import org.truffleruby.core.module.ModuleOperations;
2017
import org.truffleruby.core.module.RubyModule;
2118
import org.truffleruby.language.RubyContextSourceNode;
@@ -32,22 +29,9 @@ public static SetClassVariableNode create() {
3229

3330
public abstract Object execute(RubyModule module, String name, Object value);
3431

35-
@Specialization(
36-
guards = {
37-
"name == cachedName",
38-
"module.getClassVariables().getShape() == cachedClassVariableStorageShape",
39-
"cachedProperty != null" })
32+
@Specialization(guards = "putLibrary.putIfPresent(module.getClassVariables(), name, value)")
4033
protected Object setClassVariable(RubyModule module, String name, Object value,
41-
@Cached("name") String cachedName,
42-
@Cached("module.getClassVariables()") ClassVariableStorage cachedClassVariableStorage,
43-
@Cached("cachedClassVariableStorage.getShape()") Shape cachedClassVariableStorageShape,
44-
@Cached("cachedClassVariableStorage.getShape().getProperty(cachedName)") Property cachedProperty) {
45-
try {
46-
cachedProperty.set(cachedClassVariableStorage, value, cachedClassVariableStorageShape);
47-
} catch (IncompatibleLocationException | FinalLocationException e) {
48-
uncachedSetClassVariableNode(module, name, value);
49-
}
50-
34+
@CachedLibrary(limit = "getDynamicObjectCacheLimit()") DynamicObjectLibrary putLibrary) {
5135
return value;
5236
}
5337

0 commit comments

Comments
 (0)