dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] String#-@ deduplicates
Date: Wed, 28 Dec 2016 02:49:37 +0000	[thread overview]
Message-ID: <20161228024937.9345-1-e@80x24.org> (raw)

---
 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


                 reply	other threads:[~2016-12-28  2:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161228024937.9345-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).