From 3636e08858f62050b610b1eaa2f0d9d7a158a612 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 16 Aug 2014 03:36:47 +0000 Subject: string.c: rb_setup_fake_str * string.c (rb_setup_fake_str): setup fake string from C pointer, length, and encoding. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- symbol.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'symbol.c') diff --git a/symbol.c b/symbol.c index c50607b51b..b3fa55fab9 100644 --- a/symbol.c +++ b/symbol.c @@ -410,17 +410,6 @@ must_be_dynamic_symbol(VALUE x) } } -static VALUE -setup_fake_str(struct RString *fake_str, const char *name, long len) -{ - fake_str->basic.flags = T_STRING|RSTRING_NOEMBED; - RBASIC_SET_CLASS_RAW((VALUE)fake_str, rb_cString); - fake_str->as.heap.len = len; - fake_str->as.heap.ptr = (char *)name; - fake_str->as.heap.aux.capa = len; - return (VALUE)fake_str; -} - static VALUE dsymbol_alloc(const VALUE klass, const VALUE str, rb_encoding * const enc) { @@ -527,8 +516,7 @@ rb_intern_cstr_without_pindown(const char *name, long len, rb_encoding *enc) { st_data_t id; struct RString fake_str; - VALUE str = setup_fake_str(&fake_str, name, len); - rb_enc_associate(str, enc); + VALUE str = rb_setup_fake_str(&fake_str, name, len, enc); OBJ_FREEZE(str); if (st_lookup(global_symbols.str_id, str, &id)) { @@ -1045,8 +1033,7 @@ rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc) { ID id; struct RString fake_str; - const VALUE name = setup_fake_str(&fake_str, ptr, len); - rb_enc_associate(name, enc); + const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc); sym_check_asciionly(name); @@ -1069,8 +1056,7 @@ rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc) { VALUE sym; struct RString fake_str; - const VALUE name = setup_fake_str(&fake_str, ptr, len); - rb_enc_associate(name, enc); + const VALUE name = rb_setup_fake_str(&fake_str, ptr, len, enc); sym_check_asciionly(name); @@ -1095,8 +1081,9 @@ attrsetname_to_attr(VALUE name) ID id; struct RString fake_str; /* make local name by chopping '=' */ - const VALUE localname = setup_fake_str(&fake_str, RSTRING_PTR(name), RSTRING_LEN(name) - 1); - rb_enc_copy(localname, name); + const VALUE localname = rb_setup_fake_str(&fake_str, + RSTRING_PTR(name), RSTRING_LEN(name) - 1, + rb_enc_get(name)); OBJ_FREEZE(localname); if ((id = lookup_str_id(localname)) != 0) { -- cgit v1.2.3