From 5b950717b7bbcf8fa3b9362060c02badd87d2b5a Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 21 Sep 2006 22:50:32 +0000 Subject: [PATCH] * string.c (str_new3): embed shorter strings more eagerly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10991 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ string.c | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) 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;