From 213b49620d24ebebe3cf19787ee6e3448d27d046 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Thu, 10 Sep 2015 16:13:22 +0800 Subject: [PATCH] Simplfy zend_is_true --- Zend/zend_operators.h | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/Zend/zend_operators.h b/Zend/zend_operators.h index 7cb3ee1b8a..f8c155d2d2 100644 --- a/Zend/zend_operators.h +++ b/Zend/zend_operators.h @@ -282,47 +282,46 @@ ZEND_API int ZEND_FASTCALL zend_object_is_true(zval *op); static zend_always_inline int i_zend_is_true(zval *op) { - int result; + int result = 0; again: switch (Z_TYPE_P(op)) { - case IS_UNDEF: - case IS_NULL: - case IS_FALSE: - result = 0; - break; case IS_TRUE: result = 1; break; case IS_LONG: - result = (Z_LVAL_P(op)?1:0); - break; - case IS_RESOURCE: - result = (Z_RES_HANDLE_P(op)?1:0); + if (Z_LVAL_P(op)) { + result = 1; + } break; case IS_DOUBLE: - result = (Z_DVAL_P(op) ? 1 : 0); + if (Z_DVAL_P(op)) { + result = 1; + } break; case IS_STRING: - if (Z_STRLEN_P(op) == 0 - || (Z_STRLEN_P(op)==1 && Z_STRVAL_P(op)[0]=='0')) { - result = 0; - } else { + if (Z_STRLEN_P(op) > 1 || (Z_STRLEN_P(op) && Z_STRVAL_P(op)[0] != '0')) { result = 1; } break; case IS_ARRAY: - result = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0); + if (zend_hash_num_elements(Z_ARRVAL_P(op))) { + result = 1; + } break; case IS_OBJECT: result = zend_object_is_true(op); break; + case IS_RESOURCE: + if (EXPECTED(Z_RES_HANDLE_P(op))) { + result = 1; + } + break; case IS_REFERENCE: op = Z_REFVAL_P(op); goto again; break; default: - result = 0; break; } return result; -- 2.49.0