dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] String#-@ deduplicates
@ 2016-12-28  2:49 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-12-28  2:49 UTC (permalink / raw)
  To: spew

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-12-28  2:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-28  2:49 [PATCH] String#-@ deduplicates Eric Wong

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