Modified: MacRuby/branches/icu/encoding.h (3627 => 3628)
--- MacRuby/branches/icu/encoding.h 2010-02-26 01:07:51 UTC (rev 3627)
+++ MacRuby/branches/icu/encoding.h 2010-02-26 01:25:31 UTC (rev 3628)
@@ -290,7 +290,9 @@
STRING_VALID_ENCODING);
}
+VALUE mr_enc_s_is_compatible(VALUE klass, SEL sel, VALUE str1, VALUE str2);
VALUE str_inspect(rb_str_t *str, bool dump);
+VALUE rb_str_intern_fast(VALUE str);
// The following functions should always been prefered over anything else,
// especially if this "else" is RSTRING_PTR and RSTRING_LEN.
@@ -303,8 +305,6 @@
void rb_str_append_uchar(VALUE str, UChar c);
unsigned long rb_str_hash_uchars(const UChar *chars, long chars_len);
-VALUE mr_enc_s_is_compatible(VALUE klass, SEL sel, VALUE str1, VALUE str2);
-
// Return a string object appropriate for bstr_ calls. This does nothing for
// data/binary RubyStrings.
VALUE rb_str_bstr(VALUE str);
Modified: MacRuby/branches/icu/string.c (3627 => 3628)
--- MacRuby/branches/icu/string.c 2010-02-26 01:07:51 UTC (rev 3627)
+++ MacRuby/branches/icu/string.c 2010-02-26 01:25:31 UTC (rev 3628)
@@ -1035,8 +1035,17 @@
static rb_str_t *
str_need_string(VALUE str)
{
- if (TYPE(str) != T_STRING) {
- str = rb_str_to_str(str);
+ switch (TYPE(str)) {
+ case T_SYMBOL:
+ str = rb_sym2str(str);
+ break;
+
+ case T_STRING:
+ break;
+
+ default:
+ str = rb_str_to_str(str);
+ break;
}
return IS_RSTR(str)
? (rb_str_t *)str : str_new_from_cfstring((CFStringRef)str);
@@ -1948,8 +1957,7 @@
if (OBJ_TAINTED(self) && rb_safe_level() >= 1) {
rb_raise(rb_eSecurityError, "Insecure: can't intern tainted string");
}
- str_make_data_binary(RSTR(self));
- return ID2SYM(rb_intern(RSTR(self)->data.bytes));
+ return rb_str_intern_fast(self);
}
/*
@@ -3441,6 +3449,13 @@
return str;
}
+VALUE
+rb_str_intern_fast(VALUE str)
+{
+ // TODO: this currently does 2 hash lookups, could be optimized.
+ return ID2SYM(rb_intern_str(str));
+}
+
// MRI C-API compatibility.
VALUE