* string.c (fstring_cmp): take string encoding into account when
comparing fstrings [ruby-core:57037] [Bug #8866] * test/ruby/test_string.rb: add test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42847 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dffae9a1f9
commit
7eafeaa313
@ -1,3 +1,10 @@
|
||||
Thu Sep 5 18:05:00 2013 Charlie Somerville <charliesome@ruby-lang.org>
|
||||
|
||||
* string.c (fstring_cmp): take string encoding into account when
|
||||
comparing fstrings [ruby-core:57037] [Bug #8866]
|
||||
|
||||
* test/ruby/test_string.rb: add test
|
||||
|
||||
Thu Sep 5 17:25:49 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* string.c (rb_fstring, rb_str_free): use st_data_t instead of VALUE.
|
||||
|
16
string.c
16
string.c
@ -131,11 +131,13 @@ VALUE rb_cSymbol;
|
||||
|
||||
#define STR_ENC_GET(str) rb_enc_from_index(ENCODING_GET(str))
|
||||
|
||||
static int fstring_cmp(VALUE a, VALUE b);
|
||||
|
||||
static st_table* frozen_strings;
|
||||
|
||||
static const struct st_hash_type fstring_hash_type = {
|
||||
rb_str_cmp,
|
||||
rb_str_hash
|
||||
fstring_cmp,
|
||||
rb_str_hash,
|
||||
};
|
||||
|
||||
VALUE
|
||||
@ -153,6 +155,16 @@ rb_fstring(VALUE str)
|
||||
return str;
|
||||
}
|
||||
|
||||
static int
|
||||
fstring_cmp(VALUE a, VALUE b)
|
||||
{
|
||||
int cmp = rb_str_hash_cmp(a, b);
|
||||
if (cmp != 0) {
|
||||
return cmp;
|
||||
}
|
||||
return ENCODING_GET(b) - ENCODING_GET(a);
|
||||
}
|
||||
|
||||
static inline int
|
||||
single_byte_optimizable(VALUE str)
|
||||
{
|
||||
|
@ -2249,6 +2249,13 @@ class TestString < Test::Unit::TestCase
|
||||
b = "hello"f
|
||||
assert_equal a.object_id, b.object_id
|
||||
end
|
||||
|
||||
def test_frozen_strings_are_deduplicated_with_encoding
|
||||
a = eval("# coding: utf-8\n'hello'f")
|
||||
b = eval("# coding: ascii\n'hello'f")
|
||||
assert_equal Encoding::UTF_8, a.encoding
|
||||
assert_equal Encoding::US_ASCII, b.encoding
|
||||
end
|
||||
end
|
||||
|
||||
class TestString2 < TestString
|
||||
|
Loading…
x
Reference in New Issue
Block a user