From 52dc0632faa8450af90e37ef3c2c9f30d06951a1 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 27 Jan 2020 14:47:24 +0100 Subject: [PATCH] Avoid allocating a temporary empty string in String#slice! --- string.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/string.c b/string.c index cdd987da19..4ae804b83c 100644 --- a/string.c +++ b/string.c @@ -215,6 +215,8 @@ str_make_independent(VALUE str) /* symbols for [up|down|swap]case/capitalize options */ static VALUE sym_ascii, sym_turkic, sym_lithuanian, sym_fold; +static VALUE empty_string; + static rb_encoding * get_actual_encoding(const int encidx, VALUE str) { @@ -4887,13 +4889,13 @@ rb_str_slice_bang(int argc, VALUE *argv, VALUE str) rb_check_arity(argc, 1, 2); for (i=0; i