Simplify duplicated code
The capacity of the string can be calculated using the str_capacity function.
This commit is contained in:
parent
8a8618d4f3
commit
a16cffe384
Notes:
git
2023-06-01 12:32:49 +00:00
10
string.c
10
string.c
@ -3046,7 +3046,7 @@ str_buf_cat4(VALUE str, const char *ptr, long len, bool keep_cr)
|
|||||||
}
|
}
|
||||||
if (len == 0) return 0;
|
if (len == 0) return 0;
|
||||||
|
|
||||||
long capa, total, olen, off = -1;
|
long total, olen, off = -1;
|
||||||
char *sptr;
|
char *sptr;
|
||||||
const int termlen = TERM_LEN(str);
|
const int termlen = TERM_LEN(str);
|
||||||
|
|
||||||
@ -3055,12 +3055,8 @@ str_buf_cat4(VALUE str, const char *ptr, long len, bool keep_cr)
|
|||||||
off = ptr - sptr;
|
off = ptr - sptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STR_EMBED_P(str)) {
|
long capa = str_capacity(str, termlen);
|
||||||
capa = str_embed_capa(str) - termlen;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
capa = RSTRING(str)->as.heap.aux.capa;
|
|
||||||
}
|
|
||||||
if (olen > LONG_MAX - len) {
|
if (olen > LONG_MAX - len) {
|
||||||
rb_raise(rb_eArgError, "string sizes too big");
|
rb_raise(rb_eArgError, "string sizes too big");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user