Feature #14478 ยป 0001-String-uminus-dedupes-unconditionally.patch
spec/ruby/core/string/uminus_spec.rb | ||
---|---|---|
(-"unfrozen string").should_not equal(-"another unfrozen string")
|
||
end
|
||
it "is an identity function if the string is frozen" do
|
||
it "deduplicates frozen strings" do
|
||
dynamic = %w(this string is frozen).join(' ').freeze
|
||
(-dynamic).should equal(dynamic)
|
||
dynamic.should_not equal("this string is frozen".freeze)
|
||
(-dynamic).should_not equal("this string is frozen".freeze)
|
||
(-dynamic).should_not equal(-"this string is frozen".freeze)
|
||
(-dynamic).should equal("this string is frozen".freeze)
|
||
(-dynamic).should equal(-"this string is frozen".freeze)
|
||
end
|
||
end
|
||
end
|
string.c | ||
---|---|---|
* call-seq:
|
||
* -str -> str (frozen)
|
||
*
|
||
* If the string is frozen, then return the string itself.
|
||
* Return a frozen, possibly pre-existing
|
||
* copy of the string.
|
||
*
|
||
* If the string is not frozen, return a frozen, possibly pre-existing
|
||
* copy of it.
|
||
* String will be deduplicated as long as it is not tainted,
|
||
* or has any instance vars set on it.
|
||
*/
|
||
static VALUE
|
||
str_uminus(VALUE str)
|
||
{
|
||
if (OBJ_FROZEN(str)) {
|
||
return str;
|
||
}
|
||
else {
|
||
return rb_fstring(str);
|
||
}
|
||
return rb_fstring(str);
|
||
}
|
||
RUBY_ALIAS_FUNCTION(rb_str_dup_frozen(VALUE str), rb_str_new_frozen, (str))
|
||
-
|