Permalink
Browse files

better string/symbol interaction

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/icu@3628 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 159bfbc commit 4ba7de8016f10cc1dfb21686379ec007766f310d @lrz lrz committed Feb 26, 2010
Showing with 21 additions and 6 deletions.
  1. +2 −2 encoding.h
  2. +19 −4 string.c
View
@@ -290,7 +290,9 @@ str_set_valid_encoding(rb_str_t *self, bool status)
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 @@ UChar rb_str_get_uchar(VALUE str, long pos);
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);
View
@@ -1035,8 +1035,17 @@ str_include_string(rb_str_t *self, rb_str_t *searched)
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 @@ rstr_intern(VALUE self, SEL sel)
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 @@ rb_str_new_fast(int argc, ...)
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

0 comments on commit 4ba7de8

Please sign in to comment.