string.c: trivial optimizations
* string.c (rb_str_new_frozen, str_make_independent_expand): trivial peephole optimizations. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51354 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
21dbe868f8
commit
8ea11e8e1e
11
string.c
11
string.c
@ -973,8 +973,9 @@ rb_str_new_frozen(VALUE orig)
|
|||||||
else {
|
else {
|
||||||
if (FL_TEST(orig, STR_SHARED)) {
|
if (FL_TEST(orig, STR_SHARED)) {
|
||||||
VALUE shared = RSTRING(orig)->as.heap.aux.shared;
|
VALUE shared = RSTRING(orig)->as.heap.aux.shared;
|
||||||
long ofs = RSTRING_PTR(orig) - RSTRING_PTR(shared);
|
long ofs = RSTRING(orig)->as.heap.ptr - RSTRING(shared)->as.heap.ptr;
|
||||||
long rest = RSTRING_LEN(shared) - ofs - RSTRING_LEN(orig);
|
long rest = RSTRING(shared)->as.heap.len - ofs - RSTRING(orig)->as.heap.len;
|
||||||
|
assert(!STR_EMBED_P(shared));
|
||||||
assert(OBJ_FROZEN(shared));
|
assert(OBJ_FROZEN(shared));
|
||||||
|
|
||||||
if ((ofs > 0) || (rest > 0) ||
|
if ((ofs > 0) || (rest > 0) ||
|
||||||
@ -1623,6 +1624,7 @@ static void
|
|||||||
str_make_independent_expand(VALUE str, long expand)
|
str_make_independent_expand(VALUE str, long expand)
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
|
const char *oldptr;
|
||||||
long len = RSTRING_LEN(str);
|
long len = RSTRING_LEN(str);
|
||||||
const int termlen = TERM_LEN(str);
|
const int termlen = TERM_LEN(str);
|
||||||
long capa = len + expand;
|
long capa = len + expand;
|
||||||
@ -1639,8 +1641,9 @@ str_make_independent_expand(VALUE str, long expand)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ptr = ALLOC_N(char, capa + termlen);
|
ptr = ALLOC_N(char, capa + termlen);
|
||||||
if (RSTRING_PTR(str)) {
|
oldptr = RSTRING_PTR(str);
|
||||||
memcpy(ptr, RSTRING_PTR(str), len);
|
if (oldptr) {
|
||||||
|
memcpy(ptr, oldptr, len);
|
||||||
}
|
}
|
||||||
STR_SET_NOEMBED(str);
|
STR_SET_NOEMBED(str);
|
||||||
FL_UNSET(str, STR_SHARED|STR_NOFREE);
|
FL_UNSET(str, STR_SHARED|STR_NOFREE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user