diff options
| author | mattn <[email protected]> | 2014-06-04 10:28:34 +0900 |
|---|---|---|
| committer | mattn <[email protected]> | 2014-06-04 10:28:34 +0900 |
| commit | 6d0388c68ef1156cc33ee947f1541120e5dc5909 (patch) | |
| tree | 5dfafec63eab3aaf84d729f6d63465afb7f1a5b3 | |
| parent | 5410b9c46c53cc5f5f59a67aaefcf3d639baa63d (diff) | |
| download | mruby-6d0388c68ef1156cc33ee947f1541120e5dc5909.tar.gz mruby-6d0388c68ef1156cc33ee947f1541120e5dc5909.zip | |
Refactor variable definitions
| -rw-r--r-- | mrbgems/mruby-string-utf8/src/string.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/mrbgems/mruby-string-utf8/src/string.c b/mrbgems/mruby-string-utf8/src/string.c index e47d6a725..e31eca5d3 100644 --- a/mrbgems/mruby-string-utf8/src/string.c +++ b/mrbgems/mruby-string-utf8/src/string.c @@ -677,6 +677,9 @@ mrb_str_chars(mrb_state *mrb, mrb_value self) { mrb_value result; mrb_value blk; + int ai; + mrb_int len; + mrb_value arg; char *p = RSTRING_PTR(self); char *e = p + RSTRING_LEN(self); @@ -685,9 +688,8 @@ mrb_str_chars(mrb_state *mrb, mrb_value self) result = mrb_ary_new(mrb); if (!mrb_nil_p(blk)) { - mrb_value arg; while (p < e) { - mrb_int len = utf8len((unsigned char*) p); + len = utf8len((unsigned char*) p); arg = mrb_str_new(mrb, p, len); mrb_yield_argv(mrb, blk, 1, &arg); p += len; @@ -695,8 +697,8 @@ mrb_str_chars(mrb_state *mrb, mrb_value self) return self; } while (p < e) { - int ai = mrb_gc_arena_save(mrb); - mrb_int len = utf8len((unsigned char*) p); + ai = mrb_gc_arena_save(mrb); + len = utf8len((unsigned char*) p); mrb_ary_push(mrb, result, mrb_str_new(mrb, p, len)); mrb_gc_arena_restore(mrb, ai); p += len; @@ -709,6 +711,9 @@ mrb_str_codepoints(mrb_state *mrb, mrb_value self) { mrb_value result; mrb_value blk; + int ai; + mrb_int len; + mrb_value arg; char *p = RSTRING_PTR(self); char *e = p + RSTRING_LEN(self); @@ -717,9 +722,8 @@ mrb_str_codepoints(mrb_state *mrb, mrb_value self) result = mrb_ary_new(mrb); if (!mrb_nil_p(blk)) { - mrb_value arg; while (p < e) { - mrb_int len = utf8len((unsigned char*) p); + len = utf8len((unsigned char*) p); arg = mrb_fixnum_value(utf8code((unsigned char*) p)); mrb_yield_argv(mrb, blk, 1, &arg); p += len; @@ -727,8 +731,8 @@ mrb_str_codepoints(mrb_state *mrb, mrb_value self) return self; } while (p < e) { - int ai = mrb_gc_arena_save(mrb); - mrb_int len = utf8len((unsigned char*) p); + ai = mrb_gc_arena_save(mrb); + len = utf8len((unsigned char*) p); mrb_ary_push(mrb, result, mrb_fixnum_value(utf8code((unsigned char*) p))); mrb_gc_arena_restore(mrb, ai); p += len; |
