From 1d670ab0f090c0232e2a7a619b70ebb559453331 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 3 Aug 2014 01:56:01 +0000 Subject: ext: prefer RB_TYPE_P over comparison TYPE with constants git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/tcltklib.c | 8 ++++---- ext/tk/tkutil/tkutil.c | 40 ++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'ext/tk') diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c index 27771bff29..c67b0207c5 100644 --- a/ext/tk/tcltklib.c +++ b/ext/tk/tcltklib.c @@ -3110,7 +3110,7 @@ ip_set_exc_message(interp, exc) } if (NIL_P(enc)) { encoding = (Tcl_Encoding)NULL; - } else if (TYPE(enc) == T_STRING) { + } else if (RB_TYPE_P(enc, T_STRING)) { /* encoding = Tcl_GetEncoding(interp, RSTRING_PTR(enc)); */ encoding = Tcl_GetEncoding((Tcl_Interp*)NULL, RSTRING_PTR(enc)); } else { @@ -3320,7 +3320,7 @@ tcl_protect_core(interp, proc, data) /* should not raise exception */ if (rb_obj_is_kind_of(exc, eLocalJumpError)) { VALUE reason = rb_ivar_get(exc, ID_at_reason); - if (TYPE(reason) == T_SYMBOL) { + if (RB_TYPE_P(reason, T_SYMBOL)) { if (SYM2ID(reason) == ID_return) return TCL_RETURN; @@ -7949,7 +7949,7 @@ lib_toUTF8_core(ip_obj, src, encodename) rb_thread_critical = Qtrue; if (NIL_P(encodename)) { - if (TYPE(str) == T_STRING) { + if (RB_TYPE_P(str, T_STRING)) { volatile VALUE enc; #ifdef HAVE_RUBY_ENCODING_H @@ -8127,7 +8127,7 @@ lib_fromUTF8_core(ip_obj, src, encodename) if (NIL_P(encodename)) { volatile VALUE enc; - if (TYPE(str) == T_STRING) { + if (RB_TYPE_P(str, T_STRING)) { enc = rb_attr_get(str, ID_at_enc); if (!NIL_P(enc)) { StringValue(enc); diff --git a/ext/tk/tkutil/tkutil.c b/ext/tk/tkutil/tkutil.c index fd8972645a..2cde2265e0 100644 --- a/ext/tk/tkutil/tkutil.c +++ b/ext/tk/tkutil/tkutil.c @@ -312,7 +312,7 @@ ary2list(ary, enc_flag, self) if (NIL_P(enc_flag)) { dst_enc = sys_enc; req_chk_flag = 1; - } else if (TYPE(enc_flag) == T_TRUE || TYPE(enc_flag) == T_FALSE) { + } else if (enc_flag == Qtrue || enc_flag == Qfalse) { dst_enc = enc_flag; req_chk_flag = 0; } else { @@ -323,7 +323,7 @@ ary2list(ary, enc_flag, self) /* size = RARRAY_LEN(ary); */ size = 0; for(idx = 0; idx < RARRAY_LEN(ary); idx++) { - if (TYPE(RARRAY_PTR(ary)[idx]) == T_HASH) { + if (RB_TYPE_P(RARRAY_PTR(ary)[idx], T_HASH)) { size += 2 * RHASH_SIZE(RARRAY_PTR(ary)[idx]); } else { size++; @@ -433,7 +433,7 @@ ary2list(ary, enc_flag, self) RARRAY_PTR(dst)[idx] = str_val; } val = rb_apply(cTclTkLib, ID_merge_tklist, dst); - if (TYPE(dst_enc) == T_STRING) { + if (RB_TYPE_P(dst_enc, T_STRING)) { val = rb_funcall(cTclTkLib, ID_fromUTF8, 2, val, dst_enc); rb_ivar_set(val, ID_at_enc, dst_enc); } else { @@ -466,7 +466,7 @@ ary2list2(ary, enc_flag, self) if (NIL_P(enc_flag)) { dst_enc = sys_enc; req_chk_flag = 1; - } else if (TYPE(enc_flag) == T_TRUE || TYPE(enc_flag) == T_FALSE) { + } else if (enc_flag == Qtrue || enc_flag == Qfalse) { dst_enc = enc_flag; req_chk_flag = 0; } else { @@ -527,7 +527,7 @@ ary2list2(ary, enc_flag, self) RARRAY_PTR(dst)[idx] = str_val; } val = rb_apply(cTclTkLib, ID_merge_tklist, dst); - if (TYPE(dst_enc) == T_STRING) { + if (RB_TYPE_P(dst_enc, T_STRING)) { val = rb_funcall(cTclTkLib, ID_fromUTF8, 2, val, dst_enc); rb_ivar_set(val, ID_at_enc, dst_enc); } else { @@ -561,7 +561,7 @@ assoc2kv(assoc, ary, self) for(i = 0; i < len; i++) { pair = RARRAY_PTR(assoc)[i]; - if (TYPE(pair) != T_ARRAY) { + if (!RB_TYPE_P(pair, T_ARRAY)) { rb_ary_push(dst, key2keyname(pair)); continue; } @@ -609,7 +609,7 @@ assoc2kv_enc(assoc, ary, self) for(i = 0; i < len; i++) { pair = RARRAY_PTR(assoc)[i]; - if (TYPE(pair) != T_ARRAY) { + if (!RB_TYPE_P(pair, T_ARRAY)) { rb_ary_push(dst, key2keyname(pair)); continue; } @@ -950,7 +950,7 @@ tk_conv_args(argc, argv, self) old_gc = rb_gc_disable(); for(size = 0, idx = 2; idx < argc; idx++) { - if (TYPE(argv[idx]) == T_HASH) { + if (RB_TYPE_P(argv[idx], T_HASH)) { size += 2 * RHASH_SIZE(argv[idx]); } else { size++; @@ -959,7 +959,7 @@ tk_conv_args(argc, argv, self) /* dst = rb_ary_new2(argc - 2); */ dst = rb_ary_new2(size); for(idx = 2; idx < argc; idx++) { - if (TYPE(argv[idx]) == T_HASH) { + if (RB_TYPE_P(argv[idx], T_HASH)) { if (RTEST(argv[1])) { hash2kv_enc(argv[idx], dst, self); } else { @@ -984,7 +984,7 @@ tcl2rb_bool(self, value) VALUE self; VALUE value; { - if (TYPE(value) == T_FIXNUM) { + if (RB_TYPE_P(value, T_FIXNUM)) { if (NUM2INT(value) == 0) { return Qfalse; } else { @@ -992,7 +992,7 @@ tcl2rb_bool(self, value) } } - if (TYPE(value) == T_TRUE || TYPE(value) == T_FALSE) { + if (value == Qtrue || value == Qfalse) { return value; } @@ -1281,7 +1281,7 @@ cbsubst_def_attr_aliases(self, tbl) { struct cbsubst_info *inf; - if (TYPE(tbl) != T_HASH) { + if (!RB_TYPE_P(tbl, T_HASH)) { rb_raise(rb_eArgError, "expected a Hash"); } @@ -1306,7 +1306,7 @@ cbsubst_sym_to_subst(self, sym) ID id; volatile VALUE ret; - if (TYPE(sym) != T_SYMBOL) return sym; + if (!RB_TYPE_P(sym, T_SYMBOL)) return sym; Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO), struct cbsubst_info, inf); @@ -1556,14 +1556,14 @@ cbsubst_table_setup(argc, argv, self) len = RARRAY_LEN(key_inf); for(idx = 0; idx < len; idx++) { inf = RARRAY_PTR(key_inf)[idx]; - if (TYPE(inf) != T_ARRAY) continue; + if (!RB_TYPE_P(inf, T_ARRAY)) continue; - if (TYPE(RARRAY_PTR(inf)[0]) == T_STRING) { + if (RB_TYPE_P(RARRAY_PTR(inf)[0], T_STRING)) { chr = *(RSTRING_PTR(RARRAY_PTR(inf)[0])); } else { chr = NUM2CHR(RARRAY_PTR(inf)[0]); } - if (TYPE(RARRAY_PTR(inf)[1]) == T_STRING) { + if (RB_TYPE_P(RARRAY_PTR(inf)[1], T_STRING)) { subst_inf->type[chr] = *(RSTRING_PTR(RARRAY_PTR(inf)[1])); } else { subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]); @@ -1587,7 +1587,7 @@ cbsubst_table_setup(argc, argv, self) len = RARRAY_LEN(longkey_inf); for(idx = 0; idx < len; idx++) { inf = RARRAY_PTR(longkey_inf)[idx]; - if (TYPE(inf) != T_ARRAY) continue; + if (!RB_TYPE_P(inf, T_ARRAY)) continue; chr = (unsigned char)(0x80 + idx); subst_inf->keylen[chr] = RSTRING_LEN(RARRAY_PTR(inf)[0]); @@ -1602,7 +1602,7 @@ cbsubst_table_setup(argc, argv, self) subst_inf->key[chr][RSTRING_LEN(RARRAY_PTR(inf)[0])] = '\0'; } #endif - if (TYPE(RARRAY_PTR(inf)[1]) == T_STRING) { + if (RB_TYPE_P(RARRAY_PTR(inf)[1], T_STRING)) { subst_inf->type[chr] = *(RSTRING_PTR(RARRAY_PTR(inf)[1])); } else { subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]); @@ -1624,9 +1624,9 @@ cbsubst_table_setup(argc, argv, self) len = RARRAY_LEN(proc_inf); for(idx = 0; idx < len; idx++) { inf = RARRAY_PTR(proc_inf)[idx]; - if (TYPE(inf) != T_ARRAY) continue; + if (!RB_TYPE_P(inf, T_ARRAY)) continue; rb_hash_aset(subst_inf->proc, - ((TYPE(RARRAY_PTR(inf)[0]) == T_STRING)? + (RB_TYPE_P(RARRAY_PTR(inf)[0], T_STRING)? INT2FIX(*(RSTRING_PTR(RARRAY_PTR(inf)[0]))) : RARRAY_PTR(inf)[0]), RARRAY_PTR(inf)[1]); -- cgit v1.2.3