From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS63949 64.71.152.0/24 X-Spam-Status: No, score=-2.7 required=3.0 tests=AWL,BAYES_00, RCVD_IN_DNSWL_NONE,RDNS_NONE,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=no autolearn_force=no version=3.4.1 Received: from 80x24.org (unknown [64.71.152.64]) by dcvr.yhbt.net (Postfix) with ESMTP id 3F5E51F453 for ; Fri, 26 Oct 2018 05:53:36 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH] hash.c (rb_hash_key_str): simplify and only dedupe non-singleton strings Date: Fri, 26 Oct 2018 05:53:36 +0000 Message-Id: <20181026055336.25908-1-e@80x24.org> List-Id: [ruby-core:89562] [Feature #15251] --- hash.c | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/hash.c b/hash.c index 3f278e0c03..3019ec39d1 100644 --- a/hash.c +++ b/hash.c @@ -1564,41 +1564,14 @@ hash_aset(st_data_t *key, st_data_t *val, struct update_arg *arg, int existing) return ST_CONTINUE; } -static VALUE -fstring_existing_str(VALUE str) -{ - st_data_t fstr; - st_table *tbl = rb_vm_fstring_table(); - - if (st_lookup(tbl, str, &fstr)) { - if (rb_objspace_garbage_object_p(fstr)) { - return rb_fstring(str); - } - else { - return (VALUE)fstr; - } - } - else { - return Qnil; - } -} - VALUE rb_hash_key_str(VALUE key) { - VALUE k; - int not_tainted = !RB_OBJ_TAINTED(key); - - if (not_tainted && - (k = fstring_existing_str(key)) != Qnil) { - return k; - } - else if(not_tainted) { + /* do not use use fstring if there's a singleton class */ + if (RBASIC_CLASS(key) == rb_cString && !RB_OBJ_TAINTED_RAW(key)) { return rb_fstring(key); } - else { - return rb_str_new_frozen(key); - } + return rb_str_new_frozen(key); } static int -- EW