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: AS43289 178.17.160.0/20 X-Spam-Status: No, score=-3.3 required=3.0 tests=AWL,BAYES_00, RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_ZBI,RCVD_IN_XBL,SPF_FAIL,SPF_HELO_FAIL, TO_EQ_FM_DOM_SPF_FAIL shortcircuit=no autolearn=no autolearn_force=no version=3.4.0 Received: from 80x24.org (178-17-173-22.static.host [178.17.173.22]) by dcvr.yhbt.net (Postfix) with ESMTP id 39DD8200E0 for ; Wed, 28 Dec 2016 02:49:39 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] String#-@ deduplicates Date: Wed, 28 Dec 2016 02:49:37 +0000 Message-Id: <20161228024937.9345-1-e@80x24.org> List-Id: --- string.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/string.c b/string.c index 494dc1d90e..5da463a9b6 100644 --- a/string.c +++ b/string.c @@ -296,6 +296,13 @@ fstr_update_callback(st_data_t *key, st_data_t *value, st_data_t arg, int existi } } +/* + * call-seq: + * -str -> str (frozen) + * + * Return a deduplicated, frozen string, which may be the + * given string itself if already deduplicated. + */ RUBY_FUNC_EXPORTED VALUE rb_fstring(VALUE str) @@ -2444,26 +2451,6 @@ str_uplus(VALUE str) } } -/* - * call-seq: - * -str -> str (frozen) - * - * If the string is frozen, then return the string itself. - * - * If the string is not frozen, then duplicate the string - * freeze it and return it. - */ -static VALUE -str_uminus(VALUE str) -{ - if (OBJ_FROZEN(str)) { - return str; - } - else { - return rb_str_freeze(rb_str_dup(str)); - } -} - RUBY_ALIAS_FUNCTION(rb_str_dup_frozen(VALUE str), rb_str_new_frozen, (str)) #define rb_str_dup_frozen rb_str_new_frozen @@ -10002,7 +9989,7 @@ Init_String(void) rb_define_method(rb_cString, "scrub!", str_scrub_bang, -1); rb_define_method(rb_cString, "freeze", rb_str_freeze, 0); rb_define_method(rb_cString, "+@", str_uplus, 0); - rb_define_method(rb_cString, "-@", str_uminus, 0); + rb_define_method(rb_cString, "-@", rb_fstring, 0); rb_define_method(rb_cString, "to_i", rb_str_to_i, -1); rb_define_method(rb_cString, "to_f", rb_str_to_f, 0); -- EW