From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS8473 37.123.128.0/18 X-Spam-Status: No, score=-2.8 required=3.0 tests=AWL,BAYES_00, RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,SPF_FAIL,SPF_HELO_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (h-133-148.a2.corp.bahnhof.no [37.123.133.148]) by dcvr.yhbt.net (Postfix) with ESMTP id CE17E2095A for ; Thu, 16 Mar 2017 23:57:17 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH 3/3] deduplicate static rb_str_format format strings Date: Thu, 16 Mar 2017 23:57:09 +0000 Message-Id: <20170316235709.20071-3-e@80x24.org> In-Reply-To: <20170316235709.20071-1-e@80x24.org> References: <20170316235709.20071-1-e@80x24.org> List-Id: Anybody who hits these code paths can hit them again in the future, so try deduplicating across multiple runs of these methods to reduce garbage. * string.c (str_upto_each): fstring on "%.*d" * strftime.c (rb_strftime_with_timespec): fstring on "%0*d" --- strftime.c | 3 ++- string.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/strftime.c b/strftime.c index 42e733818c..dbb593ae1e 100644 --- a/strftime.c +++ b/strftime.c @@ -820,7 +820,8 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len, VALUE args[2], result; args[0] = INT2FIX(precision); args[1] = subsec; - result = rb_str_format(2, args, rb_str_new2("%0*d")); + result = rb_str_format(2, args, + rb_fstring_cstr("%0*d")); (void)strlcpy(s, StringValueCStr(result), endp-s); s += precision; } diff --git a/string.c b/string.c index 1bfdd00e48..4c6fe2b5f9 100644 --- a/string.c +++ b/string.c @@ -4147,7 +4147,7 @@ str_upto_each(VALUE beg, VALUE end, int excl, int (*each)(VALUE, VALUE), VALUE a } else { ID op = excl ? '<' : idLE; - VALUE args[2], fmt = rb_obj_freeze(rb_usascii_str_new_cstr("%.*d")); + VALUE args[2], fmt = rb_fstring_cstr("%.*d"); args[0] = INT2FIX(width); while (rb_funcall(b, op, 1, e)) { -- EW