Skip to content

Couple of tiny changes to string #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ str_new_empty(VALUE str)
return v;
}

#define STR_BUF_MIN_SIZE 128
#define STR_BUF_MIN_SIZE 127

VALUE
rb_str_buf_new(long capa)
Expand Down Expand Up @@ -1807,6 +1807,7 @@ rb_str_resize(VALUE str, long len)
return str;
}

#define STR_MIN_NOEMBED (sizeof(void*) * 8 - 1)
static VALUE
str_buf_cat(VALUE str, const char *ptr, long len)
{
Expand All @@ -1832,12 +1833,14 @@ str_buf_cat(VALUE str, const char *ptr, long len)
}
total = RSTRING_LEN(str)+len;
if (capa <= total) {
if (capa < STR_MIN_NOEMBED)
capa = STR_MIN_NOEMBED;
while (total > capa) {
if (capa + 1 >= LONG_MAX / 2) {
capa = (total + 4095) / 4096;
break;
}
capa = (capa + 1) * 2;
capa = capa * 2 + 1;
}
RESIZE_CAPA(str, capa);
}
Expand Down