diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-08-01 16:50:44 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2018-08-25 09:16:01 +0900 |
| commit | 6681e22c71c55ae09d802dad17296a1ebe49bb13 (patch) | |
| tree | 12feeca1ccb2e6d7b63617e4354d97cb5911ebfb /src | |
| parent | 91c08d7631e0495bf29d8b8910cca2073f8b192b (diff) | |
| download | mruby-6681e22c71c55ae09d802dad17296a1ebe49bb13.tar.gz mruby-6681e22c71c55ae09d802dad17296a1ebe49bb13.zip | |
Simply use `snprintf` instead of custom `fmt_fp`,
Unless `MRB_DISABLE_STDIO` is set. `snprintf` is used anyway
if mruby is configured to use `stdio`. This change reduces 8KB
of program size on the Linux box.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fmt_fp.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/fmt_fp.c b/src/fmt_fp.c index f8a8f7904..783cc6c02 100644 --- a/src/fmt_fp.c +++ b/src/fmt_fp.c @@ -1,3 +1,5 @@ +#ifndef MRB_WITHOUT_FLOAT +#ifdef MRB_DISABLE_STDIO /* Most code in this file originates from musl (src/stdio/vfprintf.c) @@ -36,7 +38,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include <mruby.h> #include <mruby/string.h> -#ifndef MRB_WITHOUT_FLOAT struct fmt_args { mrb_state *mrb; mrb_value str; @@ -371,4 +372,17 @@ mrb_float_to_str(mrb_state *mrb, mrb_value flo, const char *fmt) } return f.str; } +#else /* MRB_DISABLE_STDIO */ +#include <mruby.h> +#include <stdio.h> + +mrb_value +mrb_float_to_str(mrb_state *mrb, mrb_value flo, const char *fmt) +{ + char buf[24]; + + snprintf(buf, sizeof(buf), fmt, mrb_float(flo)); + return mrb_str_new_cstr(mrb, buf); +} +#endif /* MRB_DISABLE_STDIO */ #endif |
