mruby-print/print.c: small refactoring.
Inline `printstr` function which is called from only one place.
#endif
#endif
-static void
-printstr(mrb_state *mrb, const char *p, mrb_int len)
+static mrb_value
+mrb_printstr(mrb_state *mrb, mrb_value self)
{
+ mrb_value s = mrb_get_arg1(mrb);
+
+ if (mrb_string_p(s)) {
+ const char *p = RSTRING_PTR(s);
+ mrb_int len = RSTRING_LEN(s);
+
#if defined(_WIN32)
if (isatty(fileno(stdout))) {
DWORD written;
@@ -29,19 +35,13 @@ printstr(mrb_state *mrb, const char *p, mrb_int len)
utf16, (DWORD)wlen, &written, NULL);
}
mrb_free(mrb, utf16);
- } else
+ }
+ else
#endif
+ {
fwrite(p, (size_t)len, 1, stdout);
- fflush(stdout);
}
-
-static mrb_value
-mrb_printstr(mrb_state *mrb, mrb_value self)
-{
- mrb_value s = mrb_get_arg1(mrb);
-
- if (mrb_string_p(s)) {
- printstr(mrb, RSTRING_PTR(s), RSTRING_LEN(s));
+ fflush(stdout);
}
return mrb_nil_value();
}
@@ -49,9 +49,7 @@ mrb_printstr(mrb_state *mrb, mrb_value self)
void
mrb_mruby_print_gem_init(mrb_state* mrb)
{
- struct RClass *krn;
- krn = mrb->kernel_module;
- mrb_define_method(mrb, krn, "__printstr__", mrb_printstr, MRB_ARGS_REQ(1));
+ mrb_define_method(mrb, mrb->kernel_module, "__printstr__", mrb_printstr, MRB_ARGS_REQ(1));
}
void
