diff --git a/ChangeLog b/ChangeLog index f1319f42a9..f0ae8cef7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,10 @@ Thu Sep 21 22:56:20 2006 Nobuyoshi Nakada * ext/extmk.rb: expand ruby executable names. +Thu Sep 21 20:19:22 2006 Yukihiro Matsumoto + + * string.c (str_new3): embed shorter strings more eagerly. + Thu Sep 21 17:44:49 2006 Yukihiro Matsumoto * string.c (rb_str_startwith): a new method to check if a string diff --git a/string.c b/string.c index 64da8f337f..a8ff285c7d 100644 --- a/string.c +++ b/string.c @@ -191,11 +191,18 @@ str_new3(VALUE klass, VALUE str) { VALUE str2 = str_alloc(klass); - FL_SET(str2, STR_NOEMBED); - RSTRING(str2)->as.heap.len = RSTRING_LEN(str); - RSTRING(str2)->as.heap.ptr = RSTRING_PTR(str); - RSTRING(str2)->as.heap.aux.shared = str; - FL_SET(str2, ELTS_SHARED); + if (RSTRING_LEN(str) <= RSTRING_EMBED_LEN_MAX) { + STR_SET_EMBED(str); + memcpy(RSTRING_PTR(str2), RSTRING_PTR(str), RSTRING_LEN(str)+1); + STR_SET_EMBED_LEN(str2, RSTRING_LEN(str)); + } + else { + FL_SET(str2, STR_NOEMBED); + RSTRING(str2)->as.heap.len = RSTRING_LEN(str); + RSTRING(str2)->as.heap.ptr = RSTRING_PTR(str); + RSTRING(str2)->as.heap.aux.shared = str; + FL_SET(str2, ELTS_SHARED); + } OBJ_INFECT(str2, str); return str2;