summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/string.c b/src/string.c
index bfe73b359..282f8d776 100644
--- a/src/string.c
+++ b/src/string.c
@@ -1671,6 +1671,18 @@ mrb_ptr_to_str(mrb_state *mrb, void *p)
return mrb_obj_value(p_str);
}
+static inline void
+str_reverse(char *p, char *e)
+{
+ char c;
+
+ while (p < e) {
+ c = *p;
+ *p++ = *e;
+ *e-- = c;
+ }
+}
+
/* 15.2.10.5.30 */
/*
* call-seq:
@@ -1714,17 +1726,12 @@ mrb_str_reverse_bang(mrb_state *mrb, mrb_value str)
{
struct RString *s = mrb_str_ptr(str);
char *p, *e;
- char c;
mrb_str_modify(mrb, s);
if (RSTR_LEN(s) > 1) {
p = RSTR_PTR(s);
e = p + RSTR_LEN(s) - 1;
- while (p < e) {
- c = *p;
- *p++ = *e;
- *e-- = c;
- }
+ str_reverse(p, e);
}
return str;
}