mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #2059 from cremno/reduce-rstring_ptr-usage
reduce RSTRING_PTR usage
This commit is contained in:
@@ -34,7 +34,7 @@ mrb_str_swapcase_bang(mrb_state *mrb, mrb_value str)
|
||||
|
||||
mrb_str_modify(mrb, s);
|
||||
p = RSTRING_PTR(str);
|
||||
pend = RSTRING_PTR(str) + RSTRING_LEN(str);
|
||||
pend = p + RSTRING_LEN(str);
|
||||
while (p < pend) {
|
||||
if (ISUPPER(*p)) {
|
||||
*p = TOLOWER(*p);
|
||||
@@ -157,7 +157,7 @@ mrb_str_end_with(mrb_state *mrb, mrb_value self)
|
||||
RSTRING_PTR(sub),
|
||||
len_r) == 0) {
|
||||
return mrb_true_value();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return mrb_false_value();
|
||||
|
||||
+4
-2
@@ -573,8 +573,10 @@ get_valid_iv_sym(mrb_state *mrb, mrb_value iv_name)
|
||||
mrb_assert(mrb_symbol_p(iv_name) || mrb_string_p(iv_name));
|
||||
|
||||
if (mrb_string_p(iv_name)) {
|
||||
iv_name_id = mrb_intern(mrb, RSTRING_PTR(iv_name), RSTRING_LEN(iv_name));
|
||||
valid_iv_name(mrb, iv_name_id, RSTRING_PTR(iv_name), RSTRING_LEN(iv_name));
|
||||
char *p = RSTRING_PTR(iv_name);
|
||||
mrb_int l = RSTRING_LEN(iv_name);
|
||||
iv_name_id = mrb_intern(mrb, p, l);
|
||||
valid_iv_name(mrb, iv_name_id, p, l);
|
||||
}
|
||||
else {
|
||||
iv_name_id = mrb_symbol(iv_name);
|
||||
|
||||
+6
-4
@@ -394,15 +394,17 @@ sym_inspect(mrb_state *mrb, mrb_value sym)
|
||||
const char *name;
|
||||
mrb_int len;
|
||||
mrb_sym id = mrb_symbol(sym);
|
||||
char *sp;
|
||||
|
||||
name = mrb_sym2name_len(mrb, id, &len);
|
||||
str = mrb_str_new(mrb, 0, len+1);
|
||||
RSTRING_PTR(str)[0] = ':';
|
||||
memcpy(RSTRING_PTR(str)+1, name, len);
|
||||
sp = RSTRING_PTR(str);
|
||||
sp[0] = ':';
|
||||
memcpy(sp+1, name, len);
|
||||
if (!symname_p(name) || strlen(name) != len) {
|
||||
str = mrb_str_dump(mrb, str);
|
||||
RSTRING_PTR(str)[0] = ':';
|
||||
RSTRING_PTR(str)[1] = '"';
|
||||
sp[0] = ':';
|
||||
sp[1] = '"';
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
+3
-2
@@ -563,10 +563,11 @@ inspect_i(mrb_state *mrb, mrb_sym sym, mrb_value v, void *p)
|
||||
const char *s;
|
||||
mrb_int len;
|
||||
mrb_value ins;
|
||||
char *sp = RSTRING_PTR(str);
|
||||
|
||||
/* need not to show internal data */
|
||||
if (RSTRING_PTR(str)[0] == '-') { /* first element */
|
||||
RSTRING_PTR(str)[0] = '#';
|
||||
if (sp[0] == '-') { /* first element */
|
||||
sp[0] = '#';
|
||||
mrb_str_cat_lit(mrb, str, " ");
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user