[前][次][番号順一覧][スレッド一覧]

ruby-changes:58180

From: Ben <ko1@a...>
Date: Wed, 9 Oct 2019 23:47:08 +0900 (JST)
Subject: [ruby-changes:58180] bb71a128eb (master): Prefer st_is_member over st_lookup with 0

https://git.ruby-lang.org/ruby.git/commit/?id=bb71a128eb

From bb71a128eb6e901d3d7deb895971a6706eb7110d Mon Sep 17 00:00:00 2001
From: Ben Woosley <ben.woosley@g...>
Date: Thu, 18 May 2017 15:59:38 -0700
Subject: Prefer st_is_member over st_lookup with 0

The st_is_member DEFINE has simpler semantics, for more readable code.

diff --git a/array.c b/array.c
index 19d9946..3aab2ec 100644
--- a/array.c
+++ b/array.c
@@ -5209,7 +5209,7 @@ flatten(VALUE ary, int level) https://github.com/ruby/ruby/blob/trunk/array.c#L5209
 	    }
 	    else {
 		id = (st_data_t)tmp;
-		if (st_lookup(memo, id, 0)) {
+		if (st_is_member(memo, id)) {
                     st_clear(memo);
 		    rb_raise(rb_eArgError, "tried to flatten recursive array");
 		}
diff --git a/class.c b/class.c
index b4aeb59..09afc72 100644
--- a/class.c
+++ b/class.c
@@ -1176,7 +1176,7 @@ method_entry_i(ID key, VALUE value, void *data) https://github.com/ruby/ruby/blob/trunk/class.c#L1176
 	if (!me) return ID_TABLE_CONTINUE;
 	if (!arg->recur && me->owner != owner) return ID_TABLE_CONTINUE;
     }
-    if (!st_lookup(arg->list, key, 0)) {
+    if (!st_is_member(arg->list, key)) {
 	if (UNDEFINED_METHOD_ENTRY_P(me)) {
 	    type = METHOD_VISI_UNDEF; /* none */
 	}
diff --git a/gc.c b/gc.c
index 9a33da0..7cc3c53 100644
--- a/gc.c
+++ b/gc.c
@@ -3634,7 +3634,7 @@ cached_object_id(VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L3634
 
         while (1) {
             /* id is the object id */
-            if (st_lookup(objspace->id_to_obj_tbl, (st_data_t)id, 0)) {
+            if (st_is_member(objspace->id_to_obj_tbl, (st_data_t)id)) {
                 objspace->profile.object_id_collisions++;
                 id += sizeof(VALUE);
             }
@@ -7515,7 +7515,7 @@ gc_is_moveable_obj(rb_objspace_t *objspace, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L7515
       case T_NODE:
       case T_CLASS:
         if (FL_TEST(obj, FL_FINALIZE)) {
-            if (st_lookup(finalizer_table, obj, 0)) {
+            if (st_is_member(finalizer_table, obj)) {
                 return FALSE;
             }
         }
diff --git a/parse.y b/parse.y
index 2fd01dd..cddeb3c 100644
--- a/parse.y
+++ b/parse.y
@@ -821,7 +821,7 @@ new_unique_key_hash(struct parser_params *p, VALUE ary, const YYLTYPE *loc) https://github.com/ruby/ruby/blob/trunk/parse.y#L821
 	    goto error;
 	}
 	if (!RB_TYPE_P(key, T_STRING)) goto error;
-	if (st_lookup(tbl, (st_data_t)RSTRING_PTR(key), 0)) goto error;
+	if (st_is_member(tbl, (st_data_t)RSTRING_PTR(key))) goto error;
 	st_insert(tbl, (st_data_t)RSTRING_PTR(key), (st_data_t)ary);
     }
     st_free_table(tbl);
@@ -11463,7 +11463,7 @@ error_duplicate_keys(struct parser_params *p, NODE *hash) https://github.com/ruby/ruby/blob/trunk/parse.y#L11463
 	if (nd_type(head) != NODE_LIT) {
 	    yyerror1(&head->nd_loc, "key must be symbol literal");
 	}
-	if (st_lookup(literal_keys, (key = head->nd_lit), 0)) {
+	if (st_is_member(literal_keys, (key = head->nd_lit))) {
 	    yyerror1(&head->nd_loc, "duplicated key name");
 	}
 	else {
diff --git a/thread.c b/thread.c
index ea0956e..eff5d39 100644
--- a/thread.c
+++ b/thread.c
@@ -3472,7 +3472,7 @@ rb_thread_key_p(VALUE self, VALUE key) https://github.com/ruby/ruby/blob/trunk/thread.c#L3472
     if (!id || local_storage == NULL) {
 	return Qfalse;
     }
-    else if (st_lookup(local_storage, id, 0)) {
+    else if (st_is_member(local_storage, id)) {
 	return Qtrue;
     }
     else {
diff --git a/variable.c b/variable.c
index aafb6f4..b0f8792 100644
--- a/variable.c
+++ b/variable.c
@@ -1335,7 +1335,7 @@ rb_ivar_defined(VALUE obj, ID id) https://github.com/ruby/ruby/blob/trunk/variable.c#L1335
 	break;
       case T_CLASS:
       case T_MODULE:
-	if (RCLASS_IV_TBL(obj) && st_lookup(RCLASS_IV_TBL(obj), (st_data_t)id, 0))
+	if (RCLASS_IV_TBL(obj) && st_is_member(RCLASS_IV_TBL(obj), (st_data_t)id))
 	    return Qtrue;
 	break;
       default:
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]