diff options
| author | Xinchen Hui <laruence@gmail.com> | 2015-09-10 16:13:22 +0800 |
|---|---|---|
| committer | Xinchen Hui <laruence@gmail.com> | 2015-09-10 16:13:22 +0800 |
| commit | 213b49620d24ebebe3cf19787ee6e3448d27d046 (patch) | |
| tree | 19fe50467a00de87d7fe0211bd5853eb22b2723f | |
| parent | f3e8675d380af8c2fe632b9133ddcc7b1a304f49 (diff) | |
| download | php-git-213b49620d24ebebe3cf19787ee6e3448d27d046.tar.gz | |
Simplfy zend_is_true
| -rw-r--r-- | Zend/zend_operators.h | 33 |
1 files 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; |
