aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2023-05-31 09:58:17 -0400
committerPeter Zhu <peter@peterzhu.ca>2023-06-01 08:32:29 -0400
commita16cffe384ab167c22b4ae44c05950732cec2ae6 (patch)
tree6babc173b92ebe0574b16f92db0d5291c42fb765 /string.c
parent8a8618d4f3b35a5f114a3a5e05c80a7edb30546c (diff)
downloadruby-a16cffe384ab167c22b4ae44c05950732cec2ae6.tar.gz
Simplify duplicated code
The capacity of the string can be calculated using the str_capacity function.
Diffstat (limited to 'string.c')
-rw-r--r--string.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/string.c b/string.c
index aba5f47535..3c27646d5e 100644
--- a/string.c
+++ b/string.c
@@ -3046,7 +3046,7 @@ str_buf_cat4(VALUE str, const char *ptr, long len, bool keep_cr)
}
if (len == 0) return 0;
- long capa, total, olen, off = -1;
+ long total, olen, off = -1;
char *sptr;
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;
}
- if (STR_EMBED_P(str)) {
- capa = str_embed_capa(str) - termlen;
- }
- else {
- capa = RSTRING(str)->as.heap.aux.capa;
- }
+ long capa = str_capacity(str, termlen);
+
if (olen > LONG_MAX - len) {
rb_raise(rb_eArgError, "string sizes too big");
}