From cd502421462db2ad588cf8fe8c80a590f3d6f640 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Mon, 16 Jul 2012 17:54:13 +0900 Subject: Reduce strlen(). refs #301 --- src/dump.c | 9 +++++---- src/vm.c | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/dump.c b/src/dump.c index a720090fa..d8768f771 100644 --- a/src/dump.c +++ b/src/dump.c @@ -222,15 +222,16 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep, int type) for (pool_no = 0; pool_no < irep->plen; pool_no++) { uint16_t nlen =0; + int len; switch (irep->pool[pool_no].tt) { case MRB_TT_FIXNUM: - sprintf( buf, "%d", irep->pool[pool_no].value.i); - size += strlen(buf); + len = sprintf( buf, "%d", irep->pool[pool_no].value.i); + size += (uint32_t)len; break; case MRB_TT_FLOAT: - sprintf( buf, "%.16e", irep->pool[pool_no].value.f); - size += strlen(buf); + len = sprintf( buf, "%.16e", irep->pool[pool_no].value.f); + size += (uint32_t)len; break; case MRB_TT_STRING: str = mrb_string_value( mrb, &irep->pool[pool_no]); diff --git a/src/vm.c b/src/vm.c index ef323f785..bd3d05d81 100644 --- a/src/vm.c +++ b/src/vm.c @@ -892,8 +892,8 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) struct REnv *e = uvenv(mrb, lv-1); if (!e) { mrb_value exc; - const char *m = "super called outside of method"; - exc = mrb_exc_new(mrb, E_NOMETHOD_ERROR, m, strlen(m)); + static const char m[] = "super called outside of method"; + exc = mrb_exc_new(mrb, E_NOMETHOD_ERROR, m, sizeof(m) - 1); mrb->exc = (struct RObject*)mrb_object(exc); goto L_RAISE; } -- cgit v1.2.3