]> granicus.if.org Git - php/commitdiff
Fix array_search and in_array. Now binary safe, and faster (returns when
authorJeroen van Wolffelaar <jeroen@php.net>
Fri, 5 Oct 2001 21:58:41 +0000 (21:58 +0000)
committerJeroen van Wolffelaar <jeroen@php.net>
Fri, 5 Oct 2001 21:58:41 +0000 (21:58 +0000)
found, and doesn't duplicate the key each time, but only when necessary)

Patch also by Edin Kadribasic

ext/standard/array.c

index 922f9cf3b98e363689164ab5b00dea754882c4f1..a6cea5e699e619c97b6bd4cf08ca7da8435d26d9 100644 (file)
@@ -1042,6 +1042,7 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior)
        HashTable *target_hash;         /* array hashtable */
        HashPosition pos;                       /* hash iterator */
        ulong num_key;
+       uint str_key_len;
        char *string_key;
        int (*compare_func)(zval *, zval *, zval * TSRMLS_DC) = is_equal_function;
        
@@ -1076,12 +1077,12 @@ static void php_search_array(INTERNAL_FUNCTION_PARAMETERS, int behavior)
                                RETURN_TRUE;
                        } else {
                                /* Return current key */
-                               switch (zend_hash_get_current_key_ex(target_hash, &string_key, NULL, &num_key, 1,  &pos)) {
+                               switch (zend_hash_get_current_key_ex(target_hash, &string_key, &str_key_len, &num_key, 0,  &pos)) {
                                        case HASH_KEY_IS_STRING:
-                                               RETVAL_STRING(string_key, 0);
+                                               RETURN_STRINGL(string_key, str_key_len-1, 1);
                                                break;
                                        case HASH_KEY_IS_LONG:
-                                               RETVAL_LONG(num_key);
+                                               RETURN_LONG(num_key);
                                                break;
                                }
                        }