9
9
*/
10
10
package org .truffleruby .language .objects .classvariables ;
11
11
12
- import com .oracle .truffle .api .dsl .Cached ;
13
12
import com .oracle .truffle .api .dsl .NodeChild ;
14
13
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 ;
19
16
import org .truffleruby .core .module .ModuleOperations ;
20
17
import org .truffleruby .core .module .RubyModule ;
21
18
import org .truffleruby .language .RubyContextSourceNode ;
@@ -32,22 +29,9 @@ public static SetClassVariableNode create() {
32
29
33
30
public abstract Object execute (RubyModule module , String name , Object value );
34
31
35
- @ Specialization (
36
- guards = {
37
- "name == cachedName" ,
38
- "module.getClassVariables().getShape() == cachedClassVariableStorageShape" ,
39
- "cachedProperty != null" })
32
+ @ Specialization (guards = "putLibrary.putIfPresent(module.getClassVariables(), name, value)" )
40
33
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 ) {
51
35
return value ;
52
36
}
53
37
0 commit comments