mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
string.c: remove unnecessary terminator space
* string.c (str_buf_cat): remove unnecessary terminator space, since the capacity does not include its length but RESIZE_CAPA() considers it. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45536 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f2ba957058
commit
5c7564c9e2
1 changed files with 2 additions and 3 deletions
5
string.c
5
string.c
|
@ -2009,7 +2009,6 @@ static VALUE
|
||||||
str_buf_cat(VALUE str, const char *ptr, long len)
|
str_buf_cat(VALUE str, const char *ptr, long len)
|
||||||
{
|
{
|
||||||
long capa, total, off = -1;
|
long capa, total, off = -1;
|
||||||
const int termlen = TERM_LEN(str);
|
|
||||||
|
|
||||||
if (ptr >= RSTRING_PTR(str) && ptr <= RSTRING_END(str)) {
|
if (ptr >= RSTRING_PTR(str) && ptr <= RSTRING_END(str)) {
|
||||||
off = ptr - RSTRING_PTR(str);
|
off = ptr - RSTRING_PTR(str);
|
||||||
|
@ -2028,11 +2027,11 @@ str_buf_cat(VALUE str, const char *ptr, long len)
|
||||||
total = RSTRING_LEN(str)+len;
|
total = RSTRING_LEN(str)+len;
|
||||||
if (capa <= total) {
|
if (capa <= total) {
|
||||||
while (total > capa) {
|
while (total > capa) {
|
||||||
if (capa + termlen >= LONG_MAX / 2) {
|
if (capa > LONG_MAX / 2) {
|
||||||
capa = (total + 4095) / 4096 * 4096;
|
capa = (total + 4095) / 4096 * 4096;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
capa = (capa + termlen) * 2;
|
capa = 2 * capa;
|
||||||
}
|
}
|
||||||
RESIZE_CAPA(str, capa);
|
RESIZE_CAPA(str, capa);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue