Prefer st_is_member over st_lookup with 0

The st_is_member DEFINE has simpler semantics, for more readable code.
This commit is contained in:
Ben Woosley 2017-05-18 15:59:38 -07:00 коммит произвёл 卜部昌平
Родитель 29e6782f5d
Коммит bb71a128eb
6 изменённых файлов: 8 добавлений и 8 удалений

Просмотреть файл

@ -5209,7 +5209,7 @@ flatten(VALUE ary, int level)
}
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");
}

Просмотреть файл

@ -1176,7 +1176,7 @@ method_entry_i(ID key, VALUE value, void *data)
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 */
}

4
gc.c
Просмотреть файл

@ -3634,7 +3634,7 @@ cached_object_id(VALUE obj)
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)
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;
}
}

Просмотреть файл

@ -821,7 +821,7 @@ new_unique_key_hash(struct parser_params *p, VALUE ary, const YYLTYPE *loc)
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)
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 {

Просмотреть файл

@ -3472,7 +3472,7 @@ rb_thread_key_p(VALUE self, VALUE key)
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 {

Просмотреть файл

@ -1335,7 +1335,7 @@ rb_ivar_defined(VALUE obj, ID id)
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: