diff options
author | charliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-05 09:07:48 +0000 |
---|---|---|
committer | charliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-05 09:07:48 +0000 |
commit | 7eafeaa31328b4074761f4b33dc2b89946fb0617 (patch) | |
tree | 47318298a3acaaa575ed505e5b37d56b736a5230 /string.c | |
parent | dffae9a1f978d5ee5130475f4ea725865ead1730 (diff) | |
download | ruby-7eafeaa31328b4074761f4b33dc2b89946fb0617.tar.gz |
* 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
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -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) { |