summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-01-04 23:07:57 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2020-01-06 15:52:39 +0900
commit111045ecada16d3c047b90a26a1ec0af06e5a323 (patch)
tree1832fd804e79961e2cf2496f96cf4adcef5edc6f /src/string.c
parent282f907f1bf172b60043f886020f1051e127b446 (diff)
downloadmruby-111045ecada16d3c047b90a26a1ec0af06e5a323.tar.gz
mruby-111045ecada16d3c047b90a26a1ec0af06e5a323.zip
Avoid creating temporary objects in `read_irep_record_1`; close #4920
The basic idea of this change is from @dearblue. Note: the arguments of `mrb_str_pool()` have changed, but the function is provided for internal use (No `MRB_API`). So basically you don't have to worry about the change.
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/string.c b/src/string.c
index 8141019b6..08c14d8e8 100644
--- a/src/string.c
+++ b/src/string.c
@@ -576,12 +576,9 @@ str_share(mrb_state *mrb, struct RString *orig, struct RString *s)
}
mrb_value
-mrb_str_pool(mrb_state *mrb, mrb_value str)
+mrb_str_pool(mrb_state *mrb, const char *p, mrb_int len, mrb_bool nofree)
{
struct RString *s = (struct RString *)mrb_malloc(mrb, sizeof(struct RString));
- struct RString *orig = mrb_str_ptr(str);
- const char *p = RSTR_PTR(orig);
- size_t len = (size_t)RSTR_LEN(orig);
s->tt = MRB_TT_STRING;
s->c = mrb->string_class;
@@ -590,7 +587,7 @@ mrb_str_pool(mrb_state *mrb, mrb_value str)
if (RSTR_EMBEDDABLE_P(len)) {
str_init_embed(s, p, len);
}
- else if (RSTR_NOFREE_P(orig)) {
+ else if (nofree) {
str_init_nofree(s, p, len);
}
else {
@@ -2242,7 +2239,7 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str)
return result;
}
-static mrb_value
+mrb_value
mrb_str_len_to_inum(mrb_state *mrb, const char *str, mrb_int len, mrb_int base, int badcheck)
{
const char *p = str;
@@ -2492,7 +2489,7 @@ mrb_str_to_i(mrb_state *mrb, mrb_value self)
#ifndef MRB_WITHOUT_FLOAT
MRB_API double
-mrb_cstr_to_dbl(mrb_state *mrb, const char * s, mrb_bool badcheck)
+mrb_cstr_to_dbl(mrb_state *mrb, const char *s, mrb_bool badcheck)
{
const char *p = s;
char *end;