diff options
author | Andrey Hristov <andrey@php.net> | 2002-09-12 08:04:42 +0000 |
---|---|---|
committer | Andrey Hristov <andrey@php.net> | 2002-09-12 08:04:42 +0000 |
commit | ad9243463890c94ecc4d41e0b5947907cd12800b (patch) | |
tree | 10b3c6cd01e25671d9c1dd8530317a504d0013eb | |
parent | e1d0acc1f590a8d89b89e3ea6c5346760d3504f2 (diff) | |
download | php-git-ad9243463890c94ecc4d41e0b5947907cd12800b.tar.gz |
Removed magic numbers about the behavior of php_array_diff - proposed by
Andi and Jon Parise.
#It is strange that I commited ZTS code but after that Edin fixed ZTS build
#when I updated - it wasn't ZTS. hmmm. anyway fixing ZTS build.
-rw-r--r-- | ext/standard/array.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index e3aaf4cefe..2685992c67 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -75,6 +75,9 @@ php_array_globals array_globals; #define COUNT_NORMAL 0 #define COUNT_RECURSIVE 1 +#define DIFF_NORMAL 0 +#define DIFF_ASSOC 1 + PHP_MINIT_FUNCTION(array) { #ifdef ZTS @@ -2621,7 +2624,7 @@ out: } /* }}} */ -static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior) +static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior TSRMLS_DC) { zval ***args = NULL; HashTable *hash; @@ -2660,9 +2663,9 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior) *list++ = p; } *list = NULL; - if (behavior == 0) { + if (behavior == DIFF_NORMAL) { zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_data_compare TSRMLS_CC); - } else if (behavior == 1) { + } else if (behavior == DIFF_ASSOC) { zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket *), array_key_compare TSRMLS_CC); } } @@ -2676,22 +2679,22 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior) while (*ptrs[0]) { c = 1; for (i = 1; i < argc; i++) { - if (behavior == 0) { + if (behavior == DIFF_NORMAL) { while (*ptrs[i] && (0 < (c = array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC)))) { ptrs[i]++; } - } else if (behavior == 1) { + } else if (behavior == DIFF_ASSOC) { while (*ptrs[i] && (0 < (c = array_key_compare(ptrs[0], ptrs[i] TSRMLS_CC)))) { ptrs[i]++; } } if (!c) { - if (behavior == 0) { + if (behavior == DIFF_NORMAL) { if (*ptrs[i]) { ptrs[i]++; } break; - } else if (behavior == 1) { + } else if (behavior == DIFF_ASSOC) { if (*ptrs[i]) { if (array_data_compare(ptrs[0], ptrs[i] TSRMLS_CC) != 0) { c = -1; @@ -2715,11 +2718,11 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior) if (!*++ptrs[0]) { goto out; } - if (behavior == 0) { + if (behavior == DIFF_NORMAL) { if (array_data_compare(ptrs[0] - 1, ptrs[0] TSRMLS_CC)) { break; } - } else if (behavior == 1) { + } else if (behavior == DIFF_ASSOC) { /* in this case no array_key_compare is needed */ break; } @@ -2731,11 +2734,11 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior) if (!*++ptrs[0]) { goto out; } - if (behavior == 0) { + if (behavior == DIFF_NORMAL) { if (array_data_compare(ptrs[0]-1, ptrs[0] TSRMLS_CC)) { break; } - } else if (behavior == 1) { + } else if (behavior == DIFF_ASSOC) { /* in this case no array_key_compare is needed */ break; } @@ -2756,7 +2759,7 @@ out: Returns the entries of arr1 that have values which are not present in any of the others arguments */ PHP_FUNCTION(array_diff) { - php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, DIFF_NORMAL TSRMLS_CC); } /* }}} */ @@ -2764,7 +2767,7 @@ PHP_FUNCTION(array_diff) Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal */ PHP_FUNCTION(array_diff_assoc) { - php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); + php_array_diff(INTERNAL_FUNCTION_PARAM_PASSTHRU, DIFF_ASSOC TSRMLS_CC); } /* }}} */ |