From aa655b9ee13b2d26de7a633049e20742b7393e52 Mon Sep 17 00:00:00 2001 From: cremno Date: Tue, 7 Jan 2014 17:56:30 +0100 Subject: remove superfluous includes - reduce compile time by a little bit (full-core: ~0.7s for me) - thanks to 'include-what-you-use' for some help - include Standard C header files before any other (coding style) --- mrbgems/mruby-bin-mirb/tools/mirb/mirb.c | 14 +++++--------- mrbgems/mruby-bin-mruby/tools/mruby/mruby.c | 8 +++----- mrbgems/mruby-hash-ext/src/hash-ext.c | 3 --- mrbgems/mruby-numeric-ext/src/numeric_ext.c | 1 - mrbgems/mruby-random/src/mt19937ar.c | 1 - mrbgems/mruby-string-ext/src/string.c | 4 ++-- mrbgems/mruby-struct/src/struct.c | 1 - 7 files changed, 10 insertions(+), 22 deletions(-) (limited to 'mrbgems') diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c index 81eef7f82..5505e8e5e 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c @@ -8,21 +8,17 @@ #include #include - -#include +#include "mruby.h" #include "mruby/array.h" -#include -#include -#include +#include "mruby/proc.h" +#include "mruby/compile.h" +#include "mruby/string.h" + #ifdef ENABLE_READLINE #include #include #include -#endif -#include - -#ifdef ENABLE_READLINE static const char *history_file_name = ".mirb_history"; char history_path[PATH_MAX]; #endif diff --git a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c index ef0ac4978..54b2f8b65 100644 --- a/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +++ b/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c @@ -1,13 +1,11 @@ +#include +#include +#include #include "mruby.h" -#include "mruby/proc.h" #include "mruby/array.h" -#include "mruby/string.h" #include "mruby/compile.h" #include "mruby/dump.h" #include "mruby/variable.h" -#include -#include -#include #ifndef ENABLE_STDIO static void diff --git a/mrbgems/mruby-hash-ext/src/hash-ext.c b/mrbgems/mruby-hash-ext/src/hash-ext.c index 94518924e..c6e72f451 100644 --- a/mrbgems/mruby-hash-ext/src/hash-ext.c +++ b/mrbgems/mruby-hash-ext/src/hash-ext.c @@ -6,11 +6,8 @@ #include "mruby.h" #include "mruby/array.h" -#include "mruby/class.h" #include "mruby/hash.h" #include "mruby/khash.h" -#include "mruby/string.h" -#include "mruby/variable.h" /* * call-seq: diff --git a/mrbgems/mruby-numeric-ext/src/numeric_ext.c b/mrbgems/mruby-numeric-ext/src/numeric_ext.c index bb6955b45..22c1668fa 100644 --- a/mrbgems/mruby-numeric-ext/src/numeric_ext.c +++ b/mrbgems/mruby-numeric-ext/src/numeric_ext.c @@ -1,6 +1,5 @@ #include #include "mruby.h" -#include "mruby/numeric.h" static mrb_value mrb_int_chr(mrb_state *mrb, mrb_value x) diff --git a/mrbgems/mruby-random/src/mt19937ar.c b/mrbgems/mruby-random/src/mt19937ar.c index 3246909e8..41ed2c00d 100644 --- a/mrbgems/mruby-random/src/mt19937ar.c +++ b/mrbgems/mruby-random/src/mt19937ar.c @@ -4,7 +4,6 @@ ** See Copyright Notice in mruby.h */ -#include #include "mt19937ar.h" /* Period parameters */ diff --git a/mrbgems/mruby-string-ext/src/string.c b/mrbgems/mruby-string-ext/src/string.c index 6718e734a..f194bbc0e 100644 --- a/mrbgems/mruby-string-ext/src/string.c +++ b/mrbgems/mruby-string-ext/src/string.c @@ -1,7 +1,7 @@ -#include "mruby.h" -#include "mruby/string.h" #include #include +#include "mruby.h" +#include "mruby/string.h" static mrb_value mrb_str_getbyte(mrb_state *mrb, mrb_value str) diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index 309684422..e6d3b0796 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -10,7 +10,6 @@ #include "mruby/array.h" #include "mruby/string.h" #include "mruby/class.h" -#include "mruby/data.h" #include "mruby/variable.h" #define RSTRUCT_ARY(st) mrb_ary_ptr(st) -- cgit v1.2.3 From 7fc9264b0fd124559c3095dbdc515f31a0b35f55 Mon Sep 17 00:00:00 2001 From: h2so5 Date: Wed, 8 Jan 2014 02:21:19 +0900 Subject: add String#reverse, String#reverse! for UTF-8 --- mrbgems/mruby-string-utf8/src/string.c | 34 ++++++++++++++++++++++++++++++++ mrbgems/mruby-string-utf8/test/string.rb | 16 +++++++++++++++ 2 files changed, 50 insertions(+) (limited to 'mrbgems') diff --git a/mrbgems/mruby-string-utf8/src/string.c b/mrbgems/mruby-string-utf8/src/string.c index 5379dd3aa..c377726a2 100644 --- a/mrbgems/mruby-string-utf8/src/string.c +++ b/mrbgems/mruby-string-utf8/src/string.c @@ -247,6 +247,38 @@ mrb_str_aref_m(mrb_state *mrb, mrb_value str) return mrb_str_aref(mrb, str, a1); } +static mrb_value +mrb_str_reverse_bang(mrb_state *mrb, mrb_value str) +{ + int utf8_len = mrb_utf8_strlen(str); + if (utf8_len > 1) { + int len = RSTRING_LEN(str); + char *buf = (char *)mrb_malloc(mrb, len); + unsigned char* p = (unsigned char*)buf; + unsigned char* e = (unsigned char*)buf + len; + unsigned char* r = (unsigned char*)RSTRING_END(str); + + memcpy(buf, RSTRING_PTR(str), len); + mrb_str_modify(mrb, mrb_str_ptr(str)); + + while (p