Reduce invocation of mrb_convert_type() from mrb_str_to_str().

This commit is contained in:
Yukihiro "Matz" Matsumoto
2019-02-05 14:20:58 +09:00
parent 02fbb2c211
commit 905fef2669
2 changed files with 13 additions and 3 deletions
+1 -1
View File
@@ -1815,7 +1815,7 @@ mrb_define_alias(mrb_state *mrb, struct RClass *klass, const char *name1, const
* show information on the thing we're attached to as well.
*/
static mrb_value
mrb_value
mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
{
mrb_value str;
+12 -2
View File
@@ -20,6 +20,7 @@
#include <mruby/class.h>
#include <mruby/range.h>
#include <mruby/string.h>
#include <mruby/numeric.h>
#include <mruby/re.h>
typedef struct mrb_shared_string {
@@ -972,13 +973,22 @@ mrb_str_equal_m(mrb_state *mrb, mrb_value str1)
return mrb_bool_value(mrb_str_equal(mrb, str1, str2));
}
/* ---------------------------------- */
mrb_value mrb_mod_to_s(mrb_state *mrb, mrb_value klass);
MRB_API mrb_value
mrb_str_to_str(mrb_state *mrb, mrb_value str)
{
if (!mrb_string_p(str)) {
switch (mrb_type(str)) {
case MRB_TT_STRING:
return str;
case MRB_TT_FIXNUM:
return mrb_fixnum_to_str(mrb, str, 10);
case MRB_TT_CLASS:
case MRB_TT_MODULE:
return mrb_mod_to_s(mrb, str);
default:
return mrb_convert_type(mrb, str, MRB_TT_STRING, "String", "to_s");
}
return str;
}
MRB_API const char*