string.c: use local variables

* string.c (str_buf_cat): use local variables instead of repeating
  macros.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-01-26 03:43:08 +00:00
parent 34d4105556
commit c0d0dd91e5

View File

@ -2167,23 +2167,29 @@ rb_str_resize(VALUE str, long len)
static VALUE
str_buf_cat(VALUE str, const char *ptr, long len)
{
long capa, total, off = -1;
long capa, total, olen, off = -1;
char *sptr;
if (ptr >= RSTRING_PTR(str) && ptr <= RSTRING_END(str)) {
off = ptr - RSTRING_PTR(str);
RSTRING_GETMEM(str, sptr, olen);
if (ptr >= sptr && ptr <= sptr + olen) {
off = ptr - sptr;
}
rb_str_modify(str);
if (len == 0) return 0;
if (STR_EMBED_P(str)) {
capa = RSTRING_EMBED_LEN_MAX;
sptr = RSTRING(str)->as.ary;
olen = RSTRING_EMBED_LEN(str);
}
else {
capa = RSTRING(str)->as.heap.aux.capa;
sptr = RSTRING(str)->as.heap.ptr;
olen = RSTRING(str)->as.heap.len;
}
if (RSTRING_LEN(str) >= LONG_MAX - len) {
if (olen >= LONG_MAX - len) {
rb_raise(rb_eArgError, "string sizes too big");
}
total = RSTRING_LEN(str)+len;
total = olen + len;
if (capa <= total) {
while (total > capa) {
if (capa > LONG_MAX / 2) {
@ -2193,11 +2199,12 @@ str_buf_cat(VALUE str, const char *ptr, long len)
capa = 2 * capa;
}
RESIZE_CAPA(str, capa);
sptr = RSTRING_PTR(str);
}
if (off != -1) {
ptr = RSTRING_PTR(str) + off;
ptr = sptr + off;
}
memcpy(RSTRING_PTR(str) + RSTRING_LEN(str), ptr, len);
memcpy(sptr + olen, ptr, len);
STR_SET_LEN(str, total);
RSTRING_PTR(str)[total] = '\0'; /* sentinel */