ruby-changes:37326
From: nobu <ko1@a...>
Date: Mon, 26 Jan 2015 12:43:23 +0900 (JST)
Subject: [ruby-changes:37326] nobu:r49407 (trunk): string.c: use local variables
nobu 2015-01-26 12:43:08 +0900 (Mon, 26 Jan 2015) New Revision: 49407 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49407 Log: string.c: use local variables * string.c (str_buf_cat): use local variables instead of repeating macros. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 49406) +++ string.c (revision 49407) @@ -2167,23 +2167,29 @@ rb_str_resize(VALUE str, long len) https://github.com/ruby/ruby/blob/trunk/string.c#L2167 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, https://github.com/ruby/ruby/blob/trunk/string.c#L2199 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 */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/