File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
spec/ruby/core/string/shared
java/org/truffleruby/core/kernel Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 38
38
dynamic . send ( @method ) . should equal ( "this string is frozen" . send ( @method ) . freeze )
39
39
end
40
40
41
+ it "does not deduplicate a frozen string when it has instance variables" do
42
+ dynamic = %w( this string is frozen ) . join ( ' ' )
43
+ dynamic . instance_variable_set ( :@a , 1 )
44
+ dynamic . freeze
45
+
46
+ dynamic . send ( @method ) . should_not equal ( "this string is frozen" . freeze )
47
+ dynamic . send ( @method ) . should_not equal ( "this string is frozen" . send ( @method ) . freeze )
48
+ dynamic . send ( @method ) . should equal ( dynamic )
49
+ end
50
+
41
51
ruby_version_is "3.0" do
42
52
it "interns the provided string if it is frozen" do
43
53
dynamic = "this string is unique and frozen #{ rand } " . freeze
Original file line number Diff line number Diff line change @@ -1150,6 +1150,29 @@ protected RubyArray instanceVariables(Object self) {
1150
1150
1151
1151
}
1152
1152
1153
+ @ Primitive (name = "any_instance_variable?" )
1154
+ public abstract static class AnyInstanceVariableNode extends PrimitiveArrayArgumentsNode {
1155
+
1156
+ @ Specialization (limit = "getDynamicObjectCacheLimit()" )
1157
+ protected boolean any (RubyDynamicObject self ,
1158
+ @ CachedLibrary ("self" ) DynamicObjectLibrary objectLibrary ) {
1159
+ Object [] keys = objectLibrary .getKeyArray (self );
1160
+
1161
+ for (Object key : keys ) {
1162
+ if (key instanceof String ) {
1163
+ return true ;
1164
+ }
1165
+ }
1166
+
1167
+ return false ;
1168
+ }
1169
+
1170
+ @ Specialization (guards = "!isRubyDynamicObject(self)" )
1171
+ protected boolean noVariablesInImmutableObject (Object self ) {
1172
+ return false ;
1173
+ }
1174
+ }
1175
+
1153
1176
@ CoreMethod (names = { "is_a?" , "kind_of?" }, required = 1 )
1154
1177
public abstract static class KernelIsANode extends CoreMethodArrayArgumentsNode {
1155
1178
Original file line number Diff line number Diff line change @@ -1247,7 +1247,7 @@ def -@
1247
1247
str = frozen? ? self : dup . freeze
1248
1248
if Primitive . string_interned? ( self )
1249
1249
self
1250
- elsif ! ( str . instance_variables ) . empty?
1250
+ elsif Primitive . any_instance_variable? ( str )
1251
1251
str
1252
1252
else
1253
1253
Primitive . string_intern ( str )
You can’t perform that action at this time.
0 commit comments