File tree Expand file tree Collapse file tree 2 files changed +26
-13
lines changed Expand file tree Collapse file tree 2 files changed +26
-13
lines changed Original file line number Diff line number Diff line change @@ -167,11 +167,9 @@ sym_set_cmp(VALUE a, VALUE b)
167
167
return rb_str_hash_cmp (sym_set_sym_get_str (a ), sym_set_sym_get_str (b )) == false;
168
168
}
169
169
170
-
171
170
static int
172
171
sym_check_asciionly (VALUE str , bool fake_str )
173
172
{
174
- if (!rb_enc_asciicompat (rb_enc_get (str ))) return FALSE;
175
173
switch (rb_enc_str_coderange (str )) {
176
174
case ENC_CODERANGE_BROKEN :
177
175
if (fake_str ) {
@@ -188,19 +186,12 @@ sym_check_asciionly(VALUE str, bool fake_str)
188
186
static VALUE
189
187
dup_string_for_create (VALUE str )
190
188
{
191
- rb_encoding * enc = rb_enc_get (str );
192
-
193
- str = rb_enc_str_new (RSTRING_PTR (str ), RSTRING_LEN (str ), enc );
189
+ int encidx = ENCODING_GET (str );
194
190
195
- rb_encoding * ascii = rb_usascii_encoding ();
196
- if (enc != ascii && sym_check_asciionly (str , false)) {
197
- rb_enc_associate (str , ascii );
191
+ if (encidx != rb_usascii_encindex () && sym_check_asciionly (str , true)) {
192
+ return rb_enc_interned_str (RSTRING_PTR (str ), RSTRING_LEN (str ), rb_usascii_encoding ());
198
193
}
199
- OBJ_FREEZE (str );
200
-
201
- str = rb_fstring (str );
202
-
203
- return str ;
194
+ return rb_bare_fstring (str );
204
195
}
205
196
206
197
static int
Original file line number Diff line number Diff line change @@ -20,6 +20,28 @@ def test_intern
20
20
assert_equal ( ':"foo=="' , "foo==" . intern . inspect )
21
21
end
22
22
23
+ def test_intern_bare_string
24
+ random = "str#{ rand } "
25
+ random . instance_variable_set ( :@ivar , 1 )
26
+ random . freeze
27
+ str = random . to_sym . name
28
+ assert_equal [ ] , str . instance_variables
29
+
30
+ random = Class . new ( String ) . new ( "str#{ rand } " ) . freeze
31
+ str = random . to_sym . name
32
+ assert_equal String , str . class
33
+
34
+ random = "utf8™#{ rand } "
35
+ random . instance_variable_set ( :@ivar , 1 )
36
+ random . freeze
37
+ str = random . to_sym . name
38
+ assert_equal [ ] , str . instance_variables
39
+
40
+ random = Class . new ( String ) . new ( "utf8™#{ rand } " ) . freeze
41
+ str = random . to_sym . name
42
+ assert_equal String , str . class
43
+ end
44
+
23
45
def test_all_symbols
24
46
x = Symbol . all_symbols
25
47
assert_kind_of ( Array , x )
You can’t perform that action at this time.
0 commit comments