summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-26 03:43:08 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-26 03:43:08 +0000
commitc0d0dd91e5fefe9de44b37ea6dee796b906a4b1b (patch)
tree65b23017b33f8113e9667aa3fe82d8613d171194 /string.c
parent34d4105556511e811fd632af7a7cebe970c08854 (diff)
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
Diffstat (limited to 'string.c')
-rw-r--r--string.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/string.c b/string.c
index f29158acf9..7e11130738 100644
--- a/string.c
+++ b/string.c
@@ -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 */