mirror of
https://github.com/php/php-src.git
synced 2024-11-24 02:15:04 +08:00
Merge branch 'zend_sort' of https://github.com/laruence/php-src
This commit is contained in:
commit
8a0bc38535
@ -56,6 +56,8 @@ PHP X.Y UPGRADE NOTES
|
||||
output buffer is created in an output buffer handler.
|
||||
. Added zend_memnstr_ex, which is based on string matching sunday algo.
|
||||
. Added zend_memnrstr, zend_memnrstr_ex.
|
||||
. Added hybrid sorting algo zend_sort for better performance.
|
||||
. Added stable sorting algo zend_insert_sort.
|
||||
|
||||
- DBA
|
||||
. dba_delete() now returns false if the key was not found for the inifile
|
||||
|
@ -13,7 +13,7 @@ libZend_la_SOURCES=\
|
||||
zend_vm_opcodes.c zend_opcode.c zend_operators.c zend_ptr_stack.c zend_stack.c \
|
||||
zend_variables.c zend.c zend_API.c zend_extensions.c zend_hash.c \
|
||||
zend_list.c zend_indent.c zend_builtin_functions.c zend_sprintf.c \
|
||||
zend_ini.c zend_qsort.c zend_objects.c zend_object_handlers.c \
|
||||
zend_ini.c zend_sort.c zend_objects.c zend_object_handlers.c \
|
||||
zend_objects_API.c zend_ts_hash.c zend_stream.c \
|
||||
zend_default_classes.c \
|
||||
zend_iterators.c zend_interfaces.c zend_exceptions.c \
|
||||
|
@ -23,21 +23,16 @@ int(4096)
|
||||
string(43) "Call to a member function compare() on null"
|
||||
int(4096)
|
||||
string(43) "Call to a member function compare() on null"
|
||||
int(4096)
|
||||
string(43) "Call to a member function compare() on null"
|
||||
int(4096)
|
||||
string(43) "Call to a member function compare() on null"
|
||||
array(5) {
|
||||
[0]=>
|
||||
int(-1)
|
||||
int(1)
|
||||
[1]=>
|
||||
int(3)
|
||||
int(4)
|
||||
[2]=>
|
||||
int(2)
|
||||
[3]=>
|
||||
int(4)
|
||||
int(3)
|
||||
[4]=>
|
||||
int(1)
|
||||
int(-1)
|
||||
}
|
||||
Alive
|
||||
|
||||
|
@ -1715,7 +1715,7 @@ static int zend_startup_module_zval(zval *zv) /* {{{ */
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void zend_sort_modules(void *base, size_t count, size_t siz, compare_func_t compare) /* {{{ */
|
||||
static void zend_sort_modules(void *base, size_t count, size_t siz, compare_func_t compare, swap_func_t swp) /* {{{ */
|
||||
{
|
||||
Bucket *b1 = base;
|
||||
Bucket *b2;
|
||||
@ -1821,7 +1821,7 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */
|
||||
|
||||
ZEND_API int zend_startup_modules(void) /* {{{ */
|
||||
{
|
||||
zend_hash_sort(&module_registry, zend_sort_modules, NULL, 0);
|
||||
zend_hash_sort_ex(&module_registry, zend_sort_modules, NULL, 0);
|
||||
zend_hash_apply(&module_registry, zend_startup_module_zval);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
@ -1661,8 +1661,47 @@ ZEND_API zval *zend_hash_get_current_data_ex(HashTable *ht, HashPosition *pos)
|
||||
}
|
||||
}
|
||||
|
||||
ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func,
|
||||
compare_func_t compar, zend_bool renumber)
|
||||
ZEND_API void zend_hash_bucket_swap(Bucket *p, Bucket *q) {
|
||||
zval val;
|
||||
zend_ulong h;
|
||||
zend_string *key;
|
||||
|
||||
ZVAL_COPY_VALUE(&val, &p->val);
|
||||
h = p->h;
|
||||
key = p->key;
|
||||
|
||||
ZVAL_COPY_VALUE(&p->val, &q->val);
|
||||
p->h = q->h;
|
||||
p->key = q->key;
|
||||
|
||||
ZVAL_COPY_VALUE(&q->val, &val);
|
||||
q->h = h;
|
||||
q->key = key;
|
||||
}
|
||||
|
||||
ZEND_API void zend_hash_bucket_renum_swap(Bucket *p, Bucket *q) {
|
||||
zval val;
|
||||
|
||||
ZVAL_COPY_VALUE(&val, &p->val);
|
||||
ZVAL_COPY_VALUE(&p->val, &q->val);
|
||||
ZVAL_COPY_VALUE(&q->val, &val);
|
||||
}
|
||||
|
||||
ZEND_API void zend_hash_bucket_packed_swap(Bucket *p, Bucket *q) {
|
||||
zval val;
|
||||
zend_ulong h;
|
||||
|
||||
ZVAL_COPY_VALUE(&val, &p->val);
|
||||
h = p->h;
|
||||
|
||||
ZVAL_COPY_VALUE(&p->val, &q->val);
|
||||
p->h = q->h;
|
||||
|
||||
ZVAL_COPY_VALUE(&q->val, &val);
|
||||
q->h = h;
|
||||
}
|
||||
|
||||
ZEND_API int zend_hash_sort_ex(HashTable *ht, sort_func_t sort, compare_func_t compar, zend_bool renumber)
|
||||
{
|
||||
Bucket *p;
|
||||
uint32_t i, j;
|
||||
@ -1686,7 +1725,9 @@ ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func,
|
||||
}
|
||||
}
|
||||
|
||||
(*sort_func)((void *) ht->arData, i, sizeof(Bucket), compar);
|
||||
sort((void *)ht->arData, i, sizeof(Bucket), compar,
|
||||
(swap_func_t)(renumber? zend_hash_bucket_renum_swap :
|
||||
((ht->u.flags & HASH_FLAG_PACKED) ? zend_hash_bucket_packed_swap : zend_hash_bucket_swap)));
|
||||
|
||||
HANDLE_BLOCK_INTERRUPTIONS();
|
||||
ht->nNumUsed = i;
|
||||
|
@ -201,13 +201,19 @@ typedef struct _HashPointer {
|
||||
ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor);
|
||||
ZEND_API void _zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, zend_bool overwrite ZEND_FILE_LINE_DC);
|
||||
ZEND_API void zend_hash_merge_ex(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, merge_checker_func_t pMergeSource, void *pParam);
|
||||
ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, zend_bool renumber);
|
||||
ZEND_API void zend_hash_bucket_swap(Bucket *p, Bucket *q);
|
||||
ZEND_API void zend_hash_bucket_renum_swap(Bucket *p, Bucket *q);
|
||||
ZEND_API void zend_hash_bucket_packed_swap(Bucket *p, Bucket *q);
|
||||
ZEND_API int zend_hash_sort_ex(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, zend_bool renumber);
|
||||
ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, zend_bool ordered);
|
||||
ZEND_API zval *zend_hash_minmax(const HashTable *ht, compare_func_t compar, uint32_t flag);
|
||||
|
||||
#define zend_hash_merge(target, source, pCopyConstructor, overwrite) \
|
||||
_zend_hash_merge(target, source, pCopyConstructor, overwrite ZEND_FILE_LINE_CC)
|
||||
|
||||
#define zend_hash_sort(ht, compare_func, renumber) \
|
||||
zend_hash_sort_ex(ht, zend_sort, compare_func, renumber)
|
||||
|
||||
#define zend_hash_num_elements(ht) \
|
||||
(ht)->nNumOfElements
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
/* $Id$ */
|
||||
|
||||
#include "zend.h"
|
||||
#include "zend_qsort.h"
|
||||
#include "zend_sort.h"
|
||||
#include "zend_API.h"
|
||||
#include "zend_ini.h"
|
||||
#include "zend_alloc.h"
|
||||
@ -202,7 +202,7 @@ static int ini_key_compare(const void *a, const void *b) /* {{{ */
|
||||
|
||||
ZEND_API void zend_ini_sort_entries(void) /* {{{ */
|
||||
{
|
||||
zend_hash_sort(EG(ini_directives), zend_qsort, ini_key_compare, 0);
|
||||
zend_hash_sort(EG(ini_directives), ini_key_compare, 0);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include "zend.h"
|
||||
#include "zend_llist.h"
|
||||
#include "zend_qsort.h"
|
||||
#include "zend_sort.h"
|
||||
|
||||
ZEND_API void zend_llist_init(zend_llist *l, size_t size, llist_dtor_func_t dtor, unsigned char persistent)
|
||||
{
|
||||
@ -33,7 +33,6 @@ ZEND_API void zend_llist_init(zend_llist *l, size_t size, llist_dtor_func_t dtor
|
||||
l->persistent = persistent;
|
||||
}
|
||||
|
||||
|
||||
ZEND_API void zend_llist_add_element(zend_llist *l, void *element)
|
||||
{
|
||||
zend_llist_element *tmp = pemalloc(sizeof(zend_llist_element)+l->size-1, l->persistent);
|
||||
@ -186,6 +185,14 @@ ZEND_API void zend_llist_apply(zend_llist *l, llist_apply_func_t func)
|
||||
}
|
||||
}
|
||||
|
||||
static void zend_llist_swap(zend_llist_element **p, zend_llist_element **q)
|
||||
{
|
||||
zend_llist_element *t;
|
||||
t = *p;
|
||||
*p = *q;
|
||||
*q = t;
|
||||
}
|
||||
|
||||
ZEND_API void zend_llist_sort(zend_llist *l, llist_compare_func_t comp_func)
|
||||
{
|
||||
size_t i;
|
||||
@ -205,7 +212,8 @@ ZEND_API void zend_llist_sort(zend_llist *l, llist_compare_func_t comp_func)
|
||||
*ptr++ = element;
|
||||
}
|
||||
|
||||
zend_qsort(elements, l->count, sizeof(zend_llist_element *), (compare_func_t) comp_func);
|
||||
zend_sort(elements, l->count, sizeof(zend_llist_element *),
|
||||
(compare_func_t) comp_func, (swap_func_t) zend_llist_swap);
|
||||
|
||||
l->head = elements[0];
|
||||
elements[0]->prev = NULL;
|
||||
|
@ -1,133 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| Zend Engine |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.00 of the Zend license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.zend.com/license/2_00.txt. |
|
||||
| If you did not receive a copy of the Zend license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@zend.com so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Authors: Sterling Hughes <sterling@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#include "zend.h"
|
||||
#include "zend_qsort.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#define QSORT_STACK_SIZE (sizeof(size_t) * CHAR_BIT)
|
||||
|
||||
static void _zend_qsort_swap(void *a, void *b, size_t siz)
|
||||
{
|
||||
register char *tmp_a_char;
|
||||
register char *tmp_b_char;
|
||||
register int *tmp_a_int;
|
||||
register int *tmp_b_int;
|
||||
register size_t i;
|
||||
int t_i;
|
||||
char t_c;
|
||||
|
||||
tmp_a_int = (int *) a;
|
||||
tmp_b_int = (int *) b;
|
||||
|
||||
for (i = sizeof(int); i <= siz; i += sizeof(int)) {
|
||||
t_i = *tmp_a_int;
|
||||
*tmp_a_int++ = *tmp_b_int;
|
||||
*tmp_b_int++ = t_i;
|
||||
}
|
||||
|
||||
tmp_a_char = (char *) tmp_a_int;
|
||||
tmp_b_char = (char *) tmp_b_int;
|
||||
|
||||
for (i = i - sizeof(int) + 1; i <= siz; ++i) {
|
||||
t_c = *tmp_a_char;
|
||||
*tmp_a_char++ = *tmp_b_char;
|
||||
*tmp_b_char++ = t_c;
|
||||
}
|
||||
}
|
||||
|
||||
ZEND_API void zend_qsort_r(void *base, size_t nmemb, size_t siz, compare_r_func_t compare, void *arg)
|
||||
{
|
||||
void *begin_stack[QSORT_STACK_SIZE];
|
||||
void *end_stack[QSORT_STACK_SIZE];
|
||||
register char *begin;
|
||||
register char *end;
|
||||
register char *seg1;
|
||||
register char *seg2;
|
||||
register char *seg2p;
|
||||
register int loop;
|
||||
uint offset;
|
||||
|
||||
begin_stack[0] = (char *) base;
|
||||
end_stack[0] = (char *) base + ((nmemb - 1) * siz);
|
||||
|
||||
for (loop = 0; loop >= 0; --loop) {
|
||||
begin = begin_stack[loop];
|
||||
end = end_stack[loop];
|
||||
|
||||
while (begin < end) {
|
||||
offset = (end - begin) >> Z_L(1);
|
||||
_zend_qsort_swap(begin, begin + (offset - (offset % siz)), siz);
|
||||
|
||||
seg1 = begin + siz;
|
||||
seg2 = end;
|
||||
|
||||
while (1) {
|
||||
for (; seg1 < seg2 && compare(begin, seg1, arg) > 0;
|
||||
seg1 += siz);
|
||||
|
||||
for (; seg2 >= seg1 && compare(seg2, begin, arg) > 0;
|
||||
seg2 -= siz);
|
||||
|
||||
if (seg1 >= seg2)
|
||||
break;
|
||||
|
||||
_zend_qsort_swap(seg1, seg2, siz);
|
||||
|
||||
seg1 += siz;
|
||||
seg2 -= siz;
|
||||
}
|
||||
|
||||
_zend_qsort_swap(begin, seg2, siz);
|
||||
|
||||
seg2p = seg2;
|
||||
|
||||
if ((seg2p - begin) <= (end - seg2p)) {
|
||||
if ((seg2p + siz) < end) {
|
||||
begin_stack[loop] = seg2p + siz;
|
||||
end_stack[loop++] = end;
|
||||
}
|
||||
end = seg2p - siz;
|
||||
}
|
||||
else {
|
||||
if ((seg2p - siz) > begin) {
|
||||
begin_stack[loop] = begin;
|
||||
end_stack[loop++] = seg2p - siz;
|
||||
}
|
||||
begin = seg2p + siz;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare)
|
||||
{
|
||||
zend_qsort_r(base, nmemb, siz, (compare_r_func_t)compare, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* c-basic-offset: 4
|
||||
* tab-width: 4
|
||||
* End:
|
||||
* vim600: fdm=marker
|
||||
* vim: noet sw=4 ts=4
|
||||
*/
|
378
Zend/zend_sort.c
Normal file
378
Zend/zend_sort.c
Normal file
@ -0,0 +1,378 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| Zend Engine |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.00 of the Zend license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available through the world-wide-web at the following url: |
|
||||
| http://www.zend.com/license/2_00.txt. |
|
||||
| If you did not receive a copy of the Zend license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@zend.com so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Authors: Xinchen Hui <laruence@php.net> |
|
||||
| Sterling Hughes <sterling@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#include "zend.h"
|
||||
#include "zend_sort.h"
|
||||
#include <limits.h>
|
||||
|
||||
#define QSORT_STACK_SIZE (sizeof(size_t) * CHAR_BIT)
|
||||
|
||||
ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare, swap_func_t swp) /* {{{ */
|
||||
{
|
||||
void *begin_stack[QSORT_STACK_SIZE];
|
||||
void *end_stack[QSORT_STACK_SIZE];
|
||||
register char *begin;
|
||||
register char *end;
|
||||
register char *seg1;
|
||||
register char *seg2;
|
||||
register char *seg2p;
|
||||
register int loop;
|
||||
uint offset;
|
||||
|
||||
begin_stack[0] = (char *) base;
|
||||
end_stack[0] = (char *) base + ((nmemb - 1) * siz);
|
||||
|
||||
for (loop = 0; loop >= 0; --loop) {
|
||||
begin = begin_stack[loop];
|
||||
end = end_stack[loop];
|
||||
|
||||
while (begin < end) {
|
||||
offset = (end - begin) >> Z_L(1);
|
||||
swp(begin, begin + (offset - (offset % siz)));
|
||||
|
||||
seg1 = begin + siz;
|
||||
seg2 = end;
|
||||
|
||||
while (1) {
|
||||
for (; seg1 < seg2 && compare(begin, seg1) > 0;
|
||||
seg1 += siz);
|
||||
|
||||
for (; seg2 >= seg1 && compare(seg2, begin) > 0;
|
||||
seg2 -= siz);
|
||||
|
||||
if (seg1 >= seg2)
|
||||
break;
|
||||
|
||||
swp(seg1, seg2);
|
||||
|
||||
seg1 += siz;
|
||||
seg2 -= siz;
|
||||
}
|
||||
|
||||
swp(begin, seg2);
|
||||
|
||||
seg2p = seg2;
|
||||
|
||||
if ((seg2p - begin) <= (end - seg2p)) {
|
||||
if ((seg2p + siz) < end) {
|
||||
begin_stack[loop] = seg2p + siz;
|
||||
end_stack[loop++] = end;
|
||||
}
|
||||
end = seg2p - siz;
|
||||
}
|
||||
else {
|
||||
if ((seg2p - siz) > begin) {
|
||||
begin_stack[loop] = begin;
|
||||
end_stack[loop++] = seg2p - siz;
|
||||
}
|
||||
begin = seg2p + siz;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static inline void zend_sort_2(void *a, void *b, compare_func_t cmp, swap_func_t swp) /* {{{ */ {
|
||||
if (cmp(a, b) <= 0) {
|
||||
return;
|
||||
}
|
||||
swp(a, b);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static inline void zend_sort_3(void *a, void *b, void *c, compare_func_t cmp, swap_func_t swp) /* {{{ */ {
|
||||
if (cmp(a, b) <= 0) {
|
||||
if (cmp(b, c) <= 0) {
|
||||
return;
|
||||
}
|
||||
swp(b, c);
|
||||
if (cmp(a, b) > 0) {
|
||||
swp(a, b);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (cmp(b, c) >= 0) {
|
||||
swp(a, c);
|
||||
return;
|
||||
}
|
||||
swp(a, b);
|
||||
if (cmp(b, c) > 0) {
|
||||
swp(b, c);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void zend_sort_4(void *a, void *b, void *c, void *d, compare_func_t cmp, swap_func_t swp) /* {{{ */ {
|
||||
zend_sort_3(a, b, c, cmp, swp);
|
||||
if (cmp(c, d) > 0) {
|
||||
swp(c, d);
|
||||
if (cmp(b, c) > 0) {
|
||||
swp(b, c);
|
||||
if (cmp(a, b) > 0) {
|
||||
swp(a, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static void zend_sort_5(void *a, void *b, void *c, void *d, void *e, compare_func_t cmp, swap_func_t swp) /* {{{ */ {
|
||||
zend_sort_4(a, b, c, d, cmp, swp);
|
||||
if (cmp(d, e) > 0) {
|
||||
swp(d, e);
|
||||
if (cmp(c, d) > 0) {
|
||||
swp(c, d);
|
||||
if (cmp(b, c) > 0) {
|
||||
swp(b, c);
|
||||
if (cmp(a, b) > 0) {
|
||||
swp(a, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
ZEND_API void zend_insert_sort(void *base, size_t nmemb, size_t siz, compare_func_t cmp, swap_func_t swp) /* {{{ */{
|
||||
switch (nmemb) {
|
||||
case 0:
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
zend_sort_2(base, base + siz, cmp, swp);
|
||||
break;
|
||||
case 3:
|
||||
zend_sort_3(base, base + siz, base + siz + siz, cmp, swp);
|
||||
break;
|
||||
case 4:
|
||||
zend_sort_4(base, base + siz, base + siz + siz, base + siz + siz + siz, cmp, swp);
|
||||
break;
|
||||
case 5:
|
||||
zend_sort_5(base, base + siz, base + siz + siz, base + siz + siz + siz, base + (siz * 4), cmp, swp);
|
||||
break;
|
||||
default:
|
||||
{
|
||||
char *i, *j, *k;
|
||||
char *start = (char *)base;
|
||||
char *end = start + (nmemb * siz);
|
||||
char *sentry = start + (6 * siz);
|
||||
for (i = start + siz; i < sentry; i += siz) {
|
||||
j = i - siz;
|
||||
if (cmp(j, i) <= 0) {
|
||||
continue;
|
||||
}
|
||||
while (j != start) {
|
||||
j -= siz;
|
||||
if (cmp(j, i) <= 0) {
|
||||
j += siz;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (k = i; k > j; k -= siz) {
|
||||
swp(k, k - siz);
|
||||
}
|
||||
}
|
||||
for (i = sentry; i < end; i += siz) {
|
||||
j = i - siz;
|
||||
if (cmp(j, i) <= 0) {
|
||||
continue;
|
||||
}
|
||||
do {
|
||||
j -= siz * 2;
|
||||
if (cmp(j, i) <= 0) {
|
||||
j += siz;
|
||||
if (cmp(j, i) <= 0) {
|
||||
j += siz;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (j == start) {
|
||||
break;
|
||||
}
|
||||
if (j == start + siz) {
|
||||
j -= siz;
|
||||
if (cmp(j, i) < 0) {
|
||||
j += siz;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} while (1);
|
||||
for (k = i; k > j; k -= siz) {
|
||||
swp(k, k - siz);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ ZEND_API void zend_sort(void *base, size_t nmemb, size_t siz, compare_func_t cmp, swap_func_t swp)
|
||||
*
|
||||
* Derived from LLVM's libc++ implementation of std::sort.
|
||||
*
|
||||
* ===========================================================================
|
||||
* libc++ License
|
||||
* ===========================================================================
|
||||
*
|
||||
* The libc++ library is dual licensed under both the University of Illinois
|
||||
* "BSD-Like" license and the MIT license. As a user of this code you may
|
||||
* choose to use it under either license. As a contributor, you agree to allow
|
||||
* your code to be used under both.
|
||||
*
|
||||
* Full text of the relevant licenses is included below.
|
||||
*
|
||||
* ===========================================================================
|
||||
*
|
||||
* University of Illinois/NCSA
|
||||
* Open Source License
|
||||
*
|
||||
* Copyright (c) 2009-2012 by the contributors listed at
|
||||
* http://llvm.org/svn/llvm-project/libcxx/trunk/CREDITS.TXT
|
||||
*
|
||||
* All rights reserved.
|
||||
*
|
||||
* Developed by:
|
||||
*
|
||||
* LLVM Team
|
||||
*
|
||||
* University of Illinois at Urbana-Champaign
|
||||
*
|
||||
* http://llvm.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal with the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimers.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimers in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the names of the LLVM Team, University of Illinois at
|
||||
* Urbana-Champaign, nor the names of its contributors may be used to
|
||||
* endorse or promote products derived from this Software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* WITH THE SOFTWARE.
|
||||
*
|
||||
* ===========================================================================
|
||||
*
|
||||
* Copyright (c) 2009-2012 by the contributors listed at
|
||||
* http://llvm.org/svn/llvm-project/libcxx/trunk/CREDITS.TXT
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
ZEND_API void zend_sort(void *base, size_t nmemb, size_t siz, compare_func_t cmp, swap_func_t swp)
|
||||
{
|
||||
while (1) {
|
||||
if (nmemb <= 16) {
|
||||
return zend_insert_sort(base, nmemb, siz, cmp, swp);
|
||||
} else {
|
||||
char *i, *j;
|
||||
char *start = (char *)base;
|
||||
char *end = start + (nmemb * siz);
|
||||
size_t offset = (nmemb >> Z_L(1));
|
||||
char *pivot = start + (offset * siz);
|
||||
|
||||
if ((nmemb >> Z_L(10))) {
|
||||
size_t delta = (offset >> Z_L(1)) * siz;
|
||||
zend_sort_5(start, start + delta, pivot, pivot + delta, end - siz, cmp, swp);
|
||||
} else {
|
||||
zend_sort_3(start, pivot, end - siz, cmp, swp);
|
||||
}
|
||||
swp(start + siz, pivot);
|
||||
pivot = start + siz;
|
||||
i = pivot + siz;
|
||||
j = end - siz;
|
||||
while (1) {
|
||||
while (cmp(i, pivot) < 0) {
|
||||
i += siz;
|
||||
if (UNEXPECTED(i == j)) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
j -= siz;
|
||||
if (UNEXPECTED(j == i)) {
|
||||
goto done;
|
||||
}
|
||||
while (cmp(pivot, j) < 0) {
|
||||
j -= siz;
|
||||
if (UNEXPECTED(j == i)) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
swp(i, j);
|
||||
i += siz;
|
||||
if (UNEXPECTED(i == j)) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
done:
|
||||
swp(pivot, i - siz);
|
||||
if ((i - siz) - start < end - i) {
|
||||
zend_sort(start, (i - start)/siz - 1, siz, cmp, swp);
|
||||
base = i;
|
||||
nmemb = (end - i)/siz;
|
||||
} else {
|
||||
zend_sort(i, (end - i)/siz, siz, cmp, swp);
|
||||
nmemb = (i - start)/siz - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* c-basic-offset: 4
|
||||
* tab-width: 4
|
||||
* End:
|
||||
* vim600: fdm=marker
|
||||
* vim: noet sw=4 ts=4
|
||||
*/
|
@ -12,22 +12,23 @@
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@zend.com so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Authors: Sterling Hughes <sterling@php.net> |
|
||||
| Authors: Xinchen Hui <laruence@php.net> |
|
||||
| Sterling Hughes <sterling@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef ZEND_QSORT_H
|
||||
#define ZEND_QSORT_H
|
||||
#ifndef ZEND_SORT_H
|
||||
#define ZEND_SORT_H
|
||||
|
||||
BEGIN_EXTERN_C()
|
||||
typedef int (*compare_r_func_t)(const void *, const void *, void *);
|
||||
ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t compare);
|
||||
ZEND_API void zend_qsort_r(void *base, size_t nmemb, size_t siz, compare_r_func_t compare, void *arg);
|
||||
ZEND_API void zend_qsort(void *base, size_t nmemb, size_t siz, compare_func_t cmp, swap_func_t swp);
|
||||
ZEND_API void zend_sort(void *base, size_t nmemb, size_t siz, compare_func_t cmp, swap_func_t swp);
|
||||
ZEND_API void zend_insert_sort(void *base, size_t nmemb, size_t siz, compare_func_t cmp, swap_func_t swp);
|
||||
END_EXTERN_C()
|
||||
|
||||
#endif /* ZEND_QSORT_H */
|
||||
#endif /* ZEND_SORT_H */
|
||||
|
||||
/*
|
||||
* Local variables:
|
@ -281,7 +281,7 @@ ZEND_API int zend_ts_hash_sort(TsHashTable *ht, sort_func_t sort_func, compare_f
|
||||
int retval;
|
||||
|
||||
begin_write(ht);
|
||||
retval = zend_hash_sort(TS_HASH(ht), sort_func, compare_func, renumber);
|
||||
retval = zend_hash_sort_ex(TS_HASH(ht), sort_func, compare_func, renumber);
|
||||
end_write(ht);
|
||||
|
||||
return retval;
|
||||
|
@ -84,7 +84,8 @@ typedef struct _zend_ast_ref zend_ast_ref;
|
||||
typedef struct _zend_ast zend_ast;
|
||||
|
||||
typedef int (*compare_func_t)(const void *, const void *);
|
||||
typedef void (*sort_func_t)(void *, size_t, size_t, compare_func_t);
|
||||
typedef void (*swap_func_t)(void *, void *);
|
||||
typedef void (*sort_func_t)(void *, size_t, size_t, compare_func_t, swap_func_t);
|
||||
typedef void (*dtor_func_t)(zval *pDest);
|
||||
typedef void (*copy_ctor_func_t)(zval *pElement);
|
||||
|
||||
|
@ -1487,7 +1487,7 @@ PHP_ADD_SOURCES(Zend, \
|
||||
zend_vm_opcodes.c zend_opcode.c zend_operators.c zend_ptr_stack.c zend_stack.c \
|
||||
zend_variables.c zend.c zend_API.c zend_extensions.c zend_hash.c \
|
||||
zend_list.c zend_indent.c zend_builtin_functions.c zend_sprintf.c \
|
||||
zend_ini.c zend_qsort.c zend_multibyte.c zend_ts_hash.c zend_stream.c \
|
||||
zend_ini.c zend_sort.c zend_multibyte.c zend_ts_hash.c zend_stream.c \
|
||||
zend_iterators.c zend_interfaces.c zend_exceptions.c zend_strtod.c zend_gc.c \
|
||||
zend_closures.c zend_float.c zend_string.c zend_signal.c zend_generators.c \
|
||||
zend_virtual_cwd.c zend_ast.c zend_objects.c zend_object_handlers.c zend_objects_API.c \
|
||||
|
@ -144,7 +144,7 @@ static int _php_regcomp(regex_t *preg, const char *pattern, int cflags)
|
||||
|
||||
if (zend_hash_num_elements(&EREG(ht_rc)) >= EREG_CACHE_SIZE) {
|
||||
/* easier than dealing with overflow as it happens */
|
||||
if (EREG(lru_counter) >= (1 << 31) || zend_hash_sort(&EREG(ht_rc), zend_qsort, ereg_lru_cmp, 0) == FAILURE) {
|
||||
if (EREG(lru_counter) >= (1 << 31) || zend_hash_sort(&EREG(ht_rc), (compare_func_t)ereg_lru_cmp, 0) == FAILURE) {
|
||||
zend_hash_clean(&EREG(ht_rc));
|
||||
EREG(lru_counter) = 0;
|
||||
} else {
|
||||
|
@ -321,7 +321,7 @@ static void collator_sort_internal( int renumber, INTERNAL_FUNCTION_PARAMETERS )
|
||||
ZVAL_COPY_VALUE(&INTL_G( current_collator ), object);
|
||||
|
||||
/* Sort specified array. */
|
||||
zend_hash_sort( hash, zend_qsort, collator_compare_func, renumber );
|
||||
zend_hash_sort(hash, collator_compare_func, renumber);
|
||||
|
||||
/* Restore saved collator. */
|
||||
ZVAL_COPY_VALUE(&INTL_G( current_collator ), &saved_collator);
|
||||
@ -345,6 +345,15 @@ PHP_FUNCTION( collator_sort )
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static collator_sortkey_swap(collator_sort_key_index_t *p, collator_sort_key_index_t *q) /* {{{ */
|
||||
{
|
||||
collator_sort_key_index_t t;
|
||||
t = *p;
|
||||
*p = *q;
|
||||
*q = t;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool Collator::sortWithSortKeys( Collator $coll, array(string) $arr )
|
||||
* Equivalent to standard PHP sort using Collator.
|
||||
* Uses ICU ucol_getSortKey for performance. }}} */
|
||||
@ -496,7 +505,8 @@ PHP_FUNCTION( collator_sort_with_sort_keys )
|
||||
sortKeyIndxBuf[j].key = sortKeyBuf + (ptrdiff_t)sortKeyIndxBuf[j].key;
|
||||
|
||||
/* sort it */
|
||||
zend_qsort( sortKeyIndxBuf, sortKeyCount, sortKeyIndxSize, collator_cmp_sort_keys );
|
||||
zend_sort( sortKeyIndxBuf, sortKeyCount,
|
||||
sortKeyIndxSize, collator_cmp_sort_keys, (swap_func_t)collator_sortkey_swap);
|
||||
|
||||
zval_ptr_dtor( array );
|
||||
/* for resulting hash we'll assign new hash keys rather then reordering */
|
||||
@ -532,7 +542,7 @@ PHP_FUNCTION( collator_asort )
|
||||
/* {{{ proto bool Collator::getSortKey( Collator $coll, string $str )
|
||||
* Get a sort key for a string from a Collator. }}} */
|
||||
/* {{{ proto bool collator_get_sort_key( Collator $coll, string $str )
|
||||
* Get a sort key for a string from a Collator. }}} */
|
||||
* Get a sort key for a string from a Collator. */
|
||||
PHP_FUNCTION( collator_get_sort_key )
|
||||
{
|
||||
char* str = NULL;
|
||||
|
@ -285,7 +285,7 @@ PHAR_ADD_ENTRY:
|
||||
|
||||
if (FAILURE != zend_hash_has_more_elements(data)) {
|
||||
efree(dir);
|
||||
if (zend_hash_sort(data, zend_qsort, phar_compare_dir_name, 0) == FAILURE) {
|
||||
if (zend_hash_sort(data, phar_compare_dir_name, 0) == FAILURE) {
|
||||
FREE_HASHTABLE(data);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "zend_hash.h"
|
||||
#include "zend_interfaces.h"
|
||||
#include "zend_operators.h"
|
||||
#include "zend_qsort.h"
|
||||
#include "zend_sort.h"
|
||||
#include "zend_vm.h"
|
||||
#include "zend_smart_str.h"
|
||||
#include "main/php_streams.h"
|
||||
|
@ -187,7 +187,7 @@ static int php_array_key_compare(const void *a, const void *b) /* {{{ */
|
||||
ZVAL_STR(&first, f->key);
|
||||
}
|
||||
|
||||
if (s->key == 0) {
|
||||
if (s->key == NULL) {
|
||||
ZVAL_LONG(&second, s->h);
|
||||
} else {
|
||||
ZVAL_STR(&second, s->key);
|
||||
@ -226,7 +226,7 @@ PHP_FUNCTION(krsort)
|
||||
|
||||
php_set_compare_func(sort_type);
|
||||
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_reverse_key_compare, 0) == FAILURE) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), php_array_reverse_key_compare, 0) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
@ -254,7 +254,7 @@ PHP_FUNCTION(ksort)
|
||||
|
||||
php_set_compare_func(sort_type);
|
||||
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_key_compare, 0) == FAILURE) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), php_array_key_compare, 0) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
@ -438,11 +438,11 @@ static void php_natsort(INTERNAL_FUNCTION_PARAMETERS, int fold_case) /* {{{ */
|
||||
}
|
||||
|
||||
if (fold_case) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_natural_case_compare, 0) == FAILURE) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), php_array_natural_case_compare, 0) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_natural_compare, 0) == FAILURE) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), php_array_natural_compare, 0) == FAILURE) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -480,7 +480,7 @@ PHP_FUNCTION(asort)
|
||||
|
||||
php_set_compare_func(sort_type);
|
||||
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_data_compare, 0) == FAILURE) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), php_array_data_compare, 0) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
@ -500,7 +500,7 @@ PHP_FUNCTION(arsort)
|
||||
|
||||
php_set_compare_func(sort_type);
|
||||
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_reverse_data_compare, 0) == FAILURE) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), php_array_reverse_data_compare, 0) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
@ -520,7 +520,7 @@ PHP_FUNCTION(sort)
|
||||
|
||||
php_set_compare_func(sort_type);
|
||||
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_data_compare, 1) == FAILURE) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), php_array_data_compare, 1) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
@ -540,7 +540,7 @@ PHP_FUNCTION(rsort)
|
||||
|
||||
php_set_compare_func(sort_type);
|
||||
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_reverse_data_compare, 1) == FAILURE) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), php_array_reverse_data_compare, 1) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
RETURN_TRUE;
|
||||
@ -633,7 +633,7 @@ PHP_FUNCTION(usort)
|
||||
refcount = Z_REFCOUNT_P(array);
|
||||
arr = Z_COUNTED_P(array);
|
||||
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_compare, 1) == FAILURE) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), php_array_user_compare, 1) == FAILURE) {
|
||||
RETVAL_FALSE;
|
||||
} else {
|
||||
if (refcount > Z_REFCOUNT_P(array)) {
|
||||
@ -678,7 +678,7 @@ PHP_FUNCTION(uasort)
|
||||
refcount = Z_REFCOUNT_P(array);
|
||||
arr = Z_COUNTED_P(array);
|
||||
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_compare, 0) == FAILURE) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), php_array_user_compare, 0) == FAILURE) {
|
||||
RETVAL_FALSE;
|
||||
} else {
|
||||
if (refcount > Z_REFCOUNT_P(array)) {
|
||||
@ -766,7 +766,7 @@ PHP_FUNCTION(uksort)
|
||||
refcount = Z_REFCOUNT_P(array);
|
||||
arr = Z_COUNTED_P(array);
|
||||
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), zend_qsort, php_array_user_key_compare, 0) == FAILURE) {
|
||||
if (zend_hash_sort(Z_ARRVAL_P(array), php_array_user_key_compare, 0) == FAILURE) {
|
||||
RETVAL_FALSE;
|
||||
} else {
|
||||
if (refcount > Z_REFCOUNT_P(array)) {
|
||||
@ -3117,6 +3117,22 @@ PHP_FUNCTION(array_change_key_case)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
struct bucketindex {
|
||||
Bucket b;
|
||||
unsigned int i;
|
||||
};
|
||||
|
||||
static void array_bucketindex_swap(void *p, void *q) /* {{{ */
|
||||
{
|
||||
struct bucketindex *f = (struct bucketindex *)p;
|
||||
struct bucketindex *g = (struct bucketindex *)q;
|
||||
struct bucketindex t;
|
||||
t = *f;
|
||||
*f = *g;
|
||||
*g = t;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto array array_unique(array input [, int sort_flags])
|
||||
Removes duplicate values from array */
|
||||
PHP_FUNCTION(array_unique)
|
||||
@ -3124,10 +3140,6 @@ PHP_FUNCTION(array_unique)
|
||||
zval *array;
|
||||
uint idx;
|
||||
Bucket *p;
|
||||
struct bucketindex {
|
||||
Bucket b;
|
||||
unsigned int i;
|
||||
};
|
||||
struct bucketindex *arTmp, *cmpdata, *lastkept;
|
||||
unsigned int i;
|
||||
zend_long sort_type = PHP_SORT_STRING;
|
||||
@ -3160,8 +3172,8 @@ PHP_FUNCTION(array_unique)
|
||||
i++;
|
||||
}
|
||||
ZVAL_UNDEF(&arTmp[i].b.val);
|
||||
zend_qsort((void *) arTmp, i, sizeof(struct bucketindex), php_array_data_compare);
|
||||
|
||||
zend_sort((void *) arTmp, i, sizeof(struct bucketindex),
|
||||
php_array_data_compare, (swap_func_t)array_bucketindex_swap);
|
||||
/* go through the sorted array and delete duplicates from the copy */
|
||||
lastkept = arTmp;
|
||||
for (cmpdata = arTmp + 1; Z_TYPE(cmpdata->b.val) != IS_UNDEF; cmpdata++) {
|
||||
@ -3484,9 +3496,11 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
|
||||
ZVAL_UNDEF(&list->val);
|
||||
if (hash->nNumOfElements > 1) {
|
||||
if (behavior == INTERSECT_NORMAL) {
|
||||
zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket), intersect_data_compare_func);
|
||||
zend_sort((void *) lists[i], hash->nNumOfElements,
|
||||
sizeof(Bucket), intersect_data_compare_func, (swap_func_t)zend_hash_bucket_swap);
|
||||
} else if (behavior & INTERSECT_ASSOC) { /* triggered also when INTERSECT_KEY */
|
||||
zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket), intersect_key_compare_func);
|
||||
zend_sort((void *) lists[i], hash->nNumOfElements,
|
||||
sizeof(Bucket), intersect_key_compare_func, (swap_func_t)zend_hash_bucket_swap);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3498,9 +3512,7 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
|
||||
/* go through the lists and look for common values */
|
||||
while (Z_TYPE(ptrs[0]->val) != IS_UNDEF) {
|
||||
if ((behavior & INTERSECT_ASSOC) /* triggered also when INTERSECT_KEY */
|
||||
&&
|
||||
key_compare_type == INTERSECT_COMP_KEY_USER) {
|
||||
|
||||
&& key_compare_type == INTERSECT_COMP_KEY_USER) {
|
||||
BG(user_compare_fci) = *fci_key;
|
||||
BG(user_compare_fci_cache) = *fci_key_cache;
|
||||
}
|
||||
@ -3904,9 +3916,11 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
|
||||
ZVAL_UNDEF(&list->val);
|
||||
if (hash->nNumOfElements > 1) {
|
||||
if (behavior == DIFF_NORMAL) {
|
||||
zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket), diff_data_compare_func);
|
||||
zend_sort((void *) lists[i], hash->nNumOfElements,
|
||||
sizeof(Bucket), diff_data_compare_func, (swap_func_t)zend_hash_bucket_swap);
|
||||
} else if (behavior & DIFF_ASSOC) { /* triggered also when DIFF_KEY */
|
||||
zend_qsort((void *) lists[i], hash->nNumOfElements, sizeof(Bucket), diff_key_compare_func);
|
||||
zend_sort((void *) lists[i], hash->nNumOfElements,
|
||||
sizeof(Bucket), diff_key_compare_func, (swap_func_t)zend_hash_bucket_swap);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4186,6 +4200,17 @@ PHPAPI int php_multisort_compare(const void *a, const void *b) /* {{{ */
|
||||
efree(arrays); \
|
||||
RETURN_FALSE;
|
||||
|
||||
static void array_bucket_p_sawp(void *p, void *q) /* {{{ */ {
|
||||
Bucket *t;
|
||||
Bucket **f = (Bucket **)p;
|
||||
Bucket **g = (Bucket **)q;
|
||||
|
||||
t = *f;
|
||||
*f = *g;
|
||||
*g = t;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...])
|
||||
Sort multiple arrays at once similar to how ORDER BY clause works in SQL */
|
||||
PHP_FUNCTION(array_multisort)
|
||||
@ -4330,7 +4355,7 @@ PHP_FUNCTION(array_multisort)
|
||||
}
|
||||
|
||||
/* Do the actual sort magic - bada-bim, bada-boom. */
|
||||
zend_qsort(indirect, array_size, sizeof(Bucket *), php_multisort_compare);
|
||||
zend_qsort(indirect, array_size, sizeof(Bucket *), php_multisort_compare, (swap_func_t)array_bucket_p_sawp);
|
||||
|
||||
/* Restructure the arrays based on sorted indirect - this is mostly taken from zend_hash_sort() function. */
|
||||
HANDLE_BLOCK_INTERRUPTIONS();
|
||||
|
@ -862,7 +862,7 @@ PHPAPI void php_print_info(int flag)
|
||||
|
||||
zend_hash_init(&sorted_registry, zend_hash_num_elements(&module_registry), NULL, NULL, 1);
|
||||
zend_hash_copy(&sorted_registry, &module_registry, NULL);
|
||||
zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0);
|
||||
zend_hash_sort(&sorted_registry, module_name_cmp, 0);
|
||||
|
||||
zend_hash_apply(&sorted_registry, _display_module_info_func);
|
||||
|
||||
|
@ -3043,7 +3043,7 @@ static void php_strtr_array(zval *return_value, zend_string *input, HashTable *p
|
||||
len = zend_hash_num_elements(&num_hash);
|
||||
if ((maxlen - (minlen - 1) - len > 0) &&
|
||||
/* smart algorithm, sort key lengths first */
|
||||
zend_hash_sort(&num_hash, zend_qsort, php_strtr_key_compare, 0) == SUCCESS) {
|
||||
zend_hash_sort(&num_hash, php_strtr_key_compare, 0) == SUCCESS) {
|
||||
|
||||
old_pos = pos = 0;
|
||||
while (pos <= slen - minlen) {
|
||||
|
@ -115,30 +115,32 @@ array(8) {
|
||||
[1]=>
|
||||
string(6) "orange"
|
||||
}
|
||||
[0]=>
|
||||
string(3) "PHP"
|
||||
[17]=>
|
||||
string(27) "PHP: Hypertext Preprocessor"
|
||||
[1000]=>
|
||||
string(4) "test"
|
||||
[1001]=>
|
||||
string(6) "monkey"
|
||||
[5]=>
|
||||
string(4) "Test"
|
||||
[1000]=>
|
||||
string(4) "test"
|
||||
[17]=>
|
||||
string(27) "PHP: Hypertext Preprocessor"
|
||||
[0]=>
|
||||
string(3) "PHP"
|
||||
[16777216]=>
|
||||
float(-0.33333333333333)
|
||||
}
|
||||
Using SORT_STRING
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
array(8) {
|
||||
[1000]=>
|
||||
string(4) "test"
|
||||
@ -216,16 +218,16 @@ Using SORT_NUMERIC:
|
||||
array(8) {
|
||||
[16777216]=>
|
||||
float(-0.33333333333333)
|
||||
[0]=>
|
||||
string(3) "PHP"
|
||||
[17]=>
|
||||
string(27) "PHP: Hypertext Preprocessor"
|
||||
[5]=>
|
||||
string(4) "Test"
|
||||
[1001]=>
|
||||
string(6) "monkey"
|
||||
[1000]=>
|
||||
string(4) "test"
|
||||
[5]=>
|
||||
string(4) "Test"
|
||||
[17]=>
|
||||
string(27) "PHP: Hypertext Preprocessor"
|
||||
[0]=>
|
||||
string(3) "PHP"
|
||||
[-1000]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
@ -238,15 +240,15 @@ array(8) {
|
||||
}
|
||||
Using SORT_STRING
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
array(8) {
|
||||
[16777216]=>
|
||||
float(-0.33333333333333)
|
||||
@ -284,10 +286,10 @@ array(8) {
|
||||
string(27) "PHP: Hypertext Preprocessor"
|
||||
[5]=>
|
||||
string(4) "Test"
|
||||
["test"]=>
|
||||
int(27)
|
||||
[0]=>
|
||||
string(3) "PHP"
|
||||
["test"]=>
|
||||
int(27)
|
||||
[-1000]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
@ -332,10 +334,10 @@ array(8) {
|
||||
string(27) "PHP: Hypertext Preprocessor"
|
||||
[5]=>
|
||||
string(4) "Test"
|
||||
["test"]=>
|
||||
int(27)
|
||||
[0]=>
|
||||
string(3) "PHP"
|
||||
["test"]=>
|
||||
int(27)
|
||||
[-1000]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
@ -403,10 +405,10 @@ array(8) {
|
||||
[1]=>
|
||||
string(6) "orange"
|
||||
}
|
||||
["test"]=>
|
||||
int(27)
|
||||
[0]=>
|
||||
string(3) "PHP"
|
||||
["test"]=>
|
||||
int(27)
|
||||
[5]=>
|
||||
string(4) "Test"
|
||||
[17]=>
|
||||
@ -528,29 +530,31 @@ array(8) {
|
||||
string(6) "orange"
|
||||
}
|
||||
[2]=>
|
||||
string(3) "PHP"
|
||||
[3]=>
|
||||
string(27) "PHP: Hypertext Preprocessor"
|
||||
[4]=>
|
||||
string(6) "monkey"
|
||||
[5]=>
|
||||
string(4) "Test"
|
||||
[6]=>
|
||||
string(4) "test"
|
||||
[3]=>
|
||||
string(6) "monkey"
|
||||
[4]=>
|
||||
string(4) "Test"
|
||||
[5]=>
|
||||
string(27) "PHP: Hypertext Preprocessor"
|
||||
[6]=>
|
||||
string(3) "PHP"
|
||||
[7]=>
|
||||
float(-0.33333333333333)
|
||||
}
|
||||
Using SORT_STRING
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
array(8) {
|
||||
[0]=>
|
||||
string(4) "test"
|
||||
@ -629,15 +633,15 @@ array(8) {
|
||||
[0]=>
|
||||
float(-0.33333333333333)
|
||||
[1]=>
|
||||
string(6) "monkey"
|
||||
string(3) "PHP"
|
||||
[2]=>
|
||||
string(4) "test"
|
||||
string(27) "PHP: Hypertext Preprocessor"
|
||||
[3]=>
|
||||
string(4) "Test"
|
||||
[4]=>
|
||||
string(27) "PHP: Hypertext Preprocessor"
|
||||
string(6) "monkey"
|
||||
[5]=>
|
||||
string(3) "PHP"
|
||||
string(4) "test"
|
||||
[6]=>
|
||||
array(2) {
|
||||
[0]=>
|
||||
@ -650,15 +654,15 @@ array(8) {
|
||||
}
|
||||
Using SORT_STRING
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
|
||||
Notice: Array to string conversion in %s002.php on line %d
|
||||
Notice: Array to string conversion in %s002.php on line 16
|
||||
array(8) {
|
||||
[0]=>
|
||||
float(-0.33333333333333)
|
||||
|
@ -91,10 +91,6 @@ Notice: Array to string conversion in %sarray_intersect_variation9.php on line %
|
||||
|
||||
Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d
|
||||
array(4) {
|
||||
[0]=>
|
||||
@ -186,14 +182,6 @@ Notice: Array to string conversion in %sarray_intersect_variation9.php on line %
|
||||
|
||||
Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d
|
||||
array(4) {
|
||||
[0]=>
|
||||
|
@ -51,10 +51,6 @@ Notice: Array to string conversion in %sarray_unique_variation8.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_unique_variation8.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_unique_variation8.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_unique_variation8.php on line %d
|
||||
|
||||
Notice: Array to string conversion in %sarray_unique_variation8.php on line %d
|
||||
array(1) {
|
||||
[0]=>
|
||||
|
@ -16,4 +16,4 @@ var_dump($a);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(1) "A"
|
||||
string(1) "B"
|
||||
|
Binary file not shown.
@ -273,54 +273,54 @@ array(11) {
|
||||
bool(true)
|
||||
array(7) {
|
||||
[2]=>
|
||||
%s(2147483648)
|
||||
int(2147483648)
|
||||
[1]=>
|
||||
int(2147483647)
|
||||
[6]=>
|
||||
int(0)
|
||||
[5]=>
|
||||
int(0)
|
||||
[6]=>
|
||||
int(0)
|
||||
[3]=>
|
||||
int(-2147483647)
|
||||
[4]=>
|
||||
%s(-2147483648)
|
||||
int(-2147483648)
|
||||
[7]=>
|
||||
%s(-2147483649)
|
||||
int(-2147483649)
|
||||
}
|
||||
- Sort_flag = SORT_REGULAR -
|
||||
bool(true)
|
||||
array(7) {
|
||||
[2]=>
|
||||
%s(2147483648)
|
||||
int(2147483648)
|
||||
[1]=>
|
||||
int(2147483647)
|
||||
[6]=>
|
||||
int(0)
|
||||
[5]=>
|
||||
int(0)
|
||||
[6]=>
|
||||
int(0)
|
||||
[3]=>
|
||||
int(-2147483647)
|
||||
[4]=>
|
||||
%s(-2147483648)
|
||||
int(-2147483648)
|
||||
[7]=>
|
||||
%s(-2147483649)
|
||||
int(-2147483649)
|
||||
}
|
||||
- Sort_flag = SORT_NUMERIC -
|
||||
bool(true)
|
||||
array(7) {
|
||||
[2]=>
|
||||
%s(2147483648)
|
||||
int(2147483648)
|
||||
[1]=>
|
||||
int(2147483647)
|
||||
[6]=>
|
||||
int(0)
|
||||
[5]=>
|
||||
int(0)
|
||||
[6]=>
|
||||
int(0)
|
||||
[3]=>
|
||||
int(-2147483647)
|
||||
[4]=>
|
||||
%s(-2147483648)
|
||||
int(-2147483648)
|
||||
[7]=>
|
||||
%s(-2147483649)
|
||||
int(-2147483649)
|
||||
}
|
||||
Done
|
||||
Done
|
||||
|
@ -47,52 +47,52 @@ echo "Done\n";
|
||||
-- Testing arsort() by supplying bool value array, 'flag' value is defualt --
|
||||
bool(true)
|
||||
array(4) {
|
||||
[3]=>
|
||||
bool(true)
|
||||
[1]=>
|
||||
bool(true)
|
||||
[4]=>
|
||||
bool(false)
|
||||
[3]=>
|
||||
bool(true)
|
||||
[2]=>
|
||||
bool(false)
|
||||
[4]=>
|
||||
bool(false)
|
||||
}
|
||||
|
||||
-- Testing arsort() by supplying bool value array, 'flag' value is SORT_REGULAR --
|
||||
bool(true)
|
||||
array(4) {
|
||||
[3]=>
|
||||
bool(true)
|
||||
[1]=>
|
||||
bool(true)
|
||||
[4]=>
|
||||
bool(false)
|
||||
[3]=>
|
||||
bool(true)
|
||||
[2]=>
|
||||
bool(false)
|
||||
[4]=>
|
||||
bool(false)
|
||||
}
|
||||
|
||||
-- Testing arsort() by supplying bool value array, 'flag' value is SORT_NUMERIC --
|
||||
bool(true)
|
||||
array(4) {
|
||||
[3]=>
|
||||
bool(true)
|
||||
[1]=>
|
||||
bool(true)
|
||||
[4]=>
|
||||
bool(false)
|
||||
[3]=>
|
||||
bool(true)
|
||||
[2]=>
|
||||
bool(false)
|
||||
[4]=>
|
||||
bool(false)
|
||||
}
|
||||
|
||||
-- Testing arsort() by supplying bool value array, 'flag' value is SORT_STRING --
|
||||
bool(true)
|
||||
array(4) {
|
||||
[3]=>
|
||||
bool(true)
|
||||
[1]=>
|
||||
bool(true)
|
||||
[4]=>
|
||||
bool(false)
|
||||
[3]=>
|
||||
bool(true)
|
||||
[2]=>
|
||||
bool(false)
|
||||
[4]=>
|
||||
bool(false)
|
||||
}
|
||||
Done
|
||||
Done
|
||||
|
@ -170,13 +170,13 @@ array(6) {
|
||||
int(19)
|
||||
[3]=>
|
||||
int(13)
|
||||
[4]=>
|
||||
int(1)
|
||||
[8]=>
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(1)
|
||||
[0]=>
|
||||
[8]=>
|
||||
int(1)
|
||||
[4]=>
|
||||
int(1)
|
||||
}
|
||||
- Sort_flag = SORT_REGULAR -
|
||||
@ -186,13 +186,13 @@ array(6) {
|
||||
int(19)
|
||||
[3]=>
|
||||
int(13)
|
||||
[4]=>
|
||||
int(1)
|
||||
[8]=>
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(1)
|
||||
[0]=>
|
||||
[8]=>
|
||||
int(1)
|
||||
[4]=>
|
||||
int(1)
|
||||
}
|
||||
|
||||
@ -255,4 +255,4 @@ array(4) {
|
||||
["a"]=>
|
||||
int(1)
|
||||
}
|
||||
Done
|
||||
Done
|
||||
|
Binary file not shown.
@ -273,54 +273,54 @@ array(11) {
|
||||
bool(true)
|
||||
array(7) {
|
||||
[7]=>
|
||||
%s(-2147483649)
|
||||
int(-2147483649)
|
||||
[4]=>
|
||||
%s(-2147483648)
|
||||
int(-2147483648)
|
||||
[3]=>
|
||||
int(-2147483647)
|
||||
[6]=>
|
||||
int(0)
|
||||
[5]=>
|
||||
int(0)
|
||||
[6]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(2147483647)
|
||||
[2]=>
|
||||
%s(2147483648)
|
||||
int(2147483648)
|
||||
}
|
||||
- Sort_flag = SORT_REGULAR -
|
||||
bool(true)
|
||||
array(7) {
|
||||
[7]=>
|
||||
%s(-2147483649)
|
||||
int(-2147483649)
|
||||
[4]=>
|
||||
%s(-2147483648)
|
||||
int(-2147483648)
|
||||
[3]=>
|
||||
int(-2147483647)
|
||||
[6]=>
|
||||
int(0)
|
||||
[5]=>
|
||||
int(0)
|
||||
[6]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(2147483647)
|
||||
[2]=>
|
||||
%s(2147483648)
|
||||
int(2147483648)
|
||||
}
|
||||
- Sort_flag = SORT_NUMERIC -
|
||||
bool(true)
|
||||
array(7) {
|
||||
[7]=>
|
||||
%s(-2147483649)
|
||||
int(-2147483649)
|
||||
[4]=>
|
||||
%s(-2147483648)
|
||||
int(-2147483648)
|
||||
[3]=>
|
||||
int(-2147483647)
|
||||
[6]=>
|
||||
int(0)
|
||||
[5]=>
|
||||
int(0)
|
||||
[6]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(2147483647)
|
||||
[2]=>
|
||||
%s(2147483648)
|
||||
int(2147483648)
|
||||
}
|
||||
Done
|
||||
|
@ -47,10 +47,10 @@ echo "Done\n";
|
||||
-- Testing asort() by supplying bool value array, 'flag' value is defualt --
|
||||
bool(true)
|
||||
array(4) {
|
||||
[4]=>
|
||||
bool(false)
|
||||
[2]=>
|
||||
bool(false)
|
||||
[4]=>
|
||||
bool(false)
|
||||
[1]=>
|
||||
bool(true)
|
||||
[3]=>
|
||||
@ -60,10 +60,10 @@ array(4) {
|
||||
-- Testing asort() by supplying bool value array, 'flag' value is SORT_REGULAR --
|
||||
bool(true)
|
||||
array(4) {
|
||||
[4]=>
|
||||
bool(false)
|
||||
[2]=>
|
||||
bool(false)
|
||||
[4]=>
|
||||
bool(false)
|
||||
[1]=>
|
||||
bool(true)
|
||||
[3]=>
|
||||
@ -73,10 +73,10 @@ array(4) {
|
||||
-- Testing asort() by supplying bool value array, 'flag' value is SORT_NUMERIC --
|
||||
bool(true)
|
||||
array(4) {
|
||||
[4]=>
|
||||
bool(false)
|
||||
[2]=>
|
||||
bool(false)
|
||||
[4]=>
|
||||
bool(false)
|
||||
[1]=>
|
||||
bool(true)
|
||||
[3]=>
|
||||
@ -86,10 +86,10 @@ array(4) {
|
||||
-- Testing asort() by supplying bool value array, 'flag' value is SORT_STRING --
|
||||
bool(true)
|
||||
array(4) {
|
||||
[4]=>
|
||||
bool(false)
|
||||
[2]=>
|
||||
bool(false)
|
||||
[4]=>
|
||||
bool(false)
|
||||
[1]=>
|
||||
bool(true)
|
||||
[3]=>
|
||||
|
@ -166,13 +166,13 @@ array(3) {
|
||||
- With default sort_flag -
|
||||
bool(true)
|
||||
array(6) {
|
||||
[4]=>
|
||||
int(1)
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(1)
|
||||
[8]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
[4]=>
|
||||
int(1)
|
||||
[3]=>
|
||||
int(13)
|
||||
@ -182,13 +182,13 @@ array(6) {
|
||||
- Sort_flag = SORT_REGULAR -
|
||||
bool(true)
|
||||
array(6) {
|
||||
[4]=>
|
||||
int(1)
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(1)
|
||||
[8]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
[4]=>
|
||||
int(1)
|
||||
[3]=>
|
||||
int(13)
|
||||
|
@ -31,13 +31,13 @@ array(6) {
|
||||
string(2) "aa"
|
||||
[1]=>
|
||||
string(2) "aa"
|
||||
[3]=>
|
||||
string(2) "bb"
|
||||
[2]=>
|
||||
string(2) "bb"
|
||||
[5]=>
|
||||
[3]=>
|
||||
string(2) "bb"
|
||||
[4]=>
|
||||
string(2) "cc"
|
||||
[6]=>
|
||||
[5]=>
|
||||
string(2) "cc"
|
||||
}
|
||||
Array
|
||||
@ -47,16 +47,16 @@ Array
|
||||
[3] => bar
|
||||
)
|
||||
array(6) {
|
||||
[4]=>
|
||||
int(0)
|
||||
[3]=>
|
||||
int(0)
|
||||
[2]=>
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(0)
|
||||
[5]=>
|
||||
[2]=>
|
||||
int(0)
|
||||
[3]=>
|
||||
int(0)
|
||||
[4]=>
|
||||
string(3) "foo"
|
||||
[6]=>
|
||||
[5]=>
|
||||
string(3) "bar"
|
||||
}
|
||||
|
@ -24,6 +24,6 @@ function magic_sort_cmp($a, $b) {
|
||||
Array
|
||||
(
|
||||
[foo] => 0
|
||||
[bar-bazbazbaz-] => 0
|
||||
[bar-bazbazbaz.] => 0
|
||||
[bar-bazbazbaz-] => 0
|
||||
)
|
||||
|
@ -24,6 +24,6 @@ function magic_sort_cmp($a, $b) {
|
||||
Array
|
||||
(
|
||||
[0] => foo
|
||||
[1] => bar-bazbazbaz-
|
||||
[2] => bar-bazbazbaz.
|
||||
[1] => bar-bazbazbaz.
|
||||
[2] => bar-bazbazbaz-
|
||||
)
|
||||
|
@ -24,6 +24,6 @@ function magic_sort_cmp($a, $b) {
|
||||
Array
|
||||
(
|
||||
[2] => foo
|
||||
[1] => bar-bazbazbaz-
|
||||
[0] => bar-bazbazbaz.
|
||||
[1] => bar-bazbazbaz-
|
||||
)
|
||||
|
Binary file not shown.
@ -87,22 +87,22 @@ array(5) {
|
||||
- With defualt sort flag -
|
||||
bool(true)
|
||||
array(3) {
|
||||
["c"]=>
|
||||
string(5) "apple"
|
||||
[0]=>
|
||||
string(6) "banana"
|
||||
["a"]=>
|
||||
string(6) "orange"
|
||||
[0]=>
|
||||
string(6) "banana"
|
||||
["c"]=>
|
||||
string(5) "apple"
|
||||
}
|
||||
- Sort flag = SORT_REGULAR -
|
||||
bool(true)
|
||||
array(3) {
|
||||
["c"]=>
|
||||
string(5) "apple"
|
||||
[0]=>
|
||||
string(6) "banana"
|
||||
["a"]=>
|
||||
string(6) "orange"
|
||||
[0]=>
|
||||
string(6) "banana"
|
||||
["c"]=>
|
||||
string(5) "apple"
|
||||
}
|
||||
|
||||
-- Iteration 3 --
|
||||
|
Binary file not shown.
@ -86,22 +86,22 @@ array(5) {
|
||||
- With defualt sort flag -
|
||||
bool(true)
|
||||
array(3) {
|
||||
["c"]=>
|
||||
string(5) "apple"
|
||||
[0]=>
|
||||
string(6) "banana"
|
||||
["a"]=>
|
||||
string(6) "orange"
|
||||
[0]=>
|
||||
string(6) "banana"
|
||||
["c"]=>
|
||||
string(5) "apple"
|
||||
}
|
||||
- Sort flag = SORT_REGULAR -
|
||||
bool(true)
|
||||
array(3) {
|
||||
["c"]=>
|
||||
string(5) "apple"
|
||||
[0]=>
|
||||
string(6) "banana"
|
||||
["a"]=>
|
||||
string(6) "orange"
|
||||
[0]=>
|
||||
string(6) "banana"
|
||||
["c"]=>
|
||||
string(5) "apple"
|
||||
}
|
||||
|
||||
-- Iteration 3 --
|
||||
|
@ -43,10 +43,10 @@ array(5) {
|
||||
-- After Sorting: --
|
||||
bool(true)
|
||||
array(5) {
|
||||
[3]=>
|
||||
string(3) "a01"
|
||||
[0]=>
|
||||
string(3) "A01"
|
||||
[3]=>
|
||||
string(3) "a01"
|
||||
[1]=>
|
||||
string(2) "a1"
|
||||
[4]=>
|
||||
@ -54,4 +54,4 @@ array(5) {
|
||||
[2]=>
|
||||
string(3) "b10"
|
||||
}
|
||||
Done
|
||||
Done
|
||||
|
@ -152,19 +152,19 @@ array(5) {
|
||||
-- Iteration 3 --
|
||||
bool(true)
|
||||
array(2) {
|
||||
[1]=>
|
||||
NULL
|
||||
[0]=>
|
||||
NULL
|
||||
[1]=>
|
||||
NULL
|
||||
}
|
||||
|
||||
-- Iteration 4 --
|
||||
bool(true)
|
||||
array(4) {
|
||||
[3]=>
|
||||
bool(false)
|
||||
[1]=>
|
||||
bool(false)
|
||||
[3]=>
|
||||
bool(false)
|
||||
[0]=>
|
||||
bool(true)
|
||||
[2]=>
|
||||
@ -174,10 +174,10 @@ array(4) {
|
||||
-- Iteration 5 --
|
||||
bool(true)
|
||||
array(2) {
|
||||
[1]=>
|
||||
string(0) ""
|
||||
[0]=>
|
||||
string(0) ""
|
||||
[1]=>
|
||||
string(0) ""
|
||||
}
|
||||
|
||||
-- Iteration 6 --
|
||||
@ -190,10 +190,10 @@ bool(true)
|
||||
array(3) {
|
||||
[2]=>
|
||||
string(11) "hello world"
|
||||
[1]=>
|
||||
string(6) "string"
|
||||
[0]=>
|
||||
string(6) "string"
|
||||
[1]=>
|
||||
string(6) "string"
|
||||
}
|
||||
|
||||
-- Iteration 8 --
|
||||
@ -224,4 +224,4 @@ array(1) {
|
||||
[0]=>
|
||||
resource(%d) of type (stream)
|
||||
}
|
||||
Done
|
||||
Done
|
||||
|
@ -41,15 +41,15 @@ array(11) {
|
||||
NULL
|
||||
[1]=>
|
||||
NULL
|
||||
[5]=>
|
||||
string(1) ""
|
||||
[6]=>
|
||||
string(1) "
|
||||
"
|
||||
[10]=>
|
||||
string(1) ""
|
||||
[7]=>
|
||||
string(1) " "
|
||||
[5]=>
|
||||
string(1) ""
|
||||
[10]=>
|
||||
string(1) ""
|
||||
[4]=>
|
||||
string(1) ""
|
||||
[2]=>
|
||||
@ -65,16 +65,16 @@ bool(true)
|
||||
array(12) {
|
||||
[3]=>
|
||||
string(5) "apple"
|
||||
[11]=>
|
||||
string(6) "BANANA"
|
||||
[2]=>
|
||||
string(6) "banana"
|
||||
[11]=>
|
||||
string(6) "BANANA"
|
||||
[0]=>
|
||||
string(5) "lemoN"
|
||||
[10]=>
|
||||
string(6) "oraNGe"
|
||||
[1]=>
|
||||
string(6) "Orange"
|
||||
[10]=>
|
||||
string(6) "oraNGe"
|
||||
[4]=>
|
||||
string(4) "Test"
|
||||
[6]=>
|
||||
|
Binary file not shown.
Binary file not shown.
@ -107,15 +107,6 @@ array(3) {
|
||||
int(6)
|
||||
}
|
||||
[1]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(5) "first"
|
||||
[5]=>
|
||||
string(6) "second"
|
||||
[6]=>
|
||||
string(5) "third"
|
||||
}
|
||||
[2]=>
|
||||
array(3) {
|
||||
["a"]=>
|
||||
string(6) "orange"
|
||||
@ -124,6 +115,15 @@ array(3) {
|
||||
["c"]=>
|
||||
string(5) "apple"
|
||||
}
|
||||
[2]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(5) "first"
|
||||
[5]=>
|
||||
string(6) "second"
|
||||
[6]=>
|
||||
string(5) "third"
|
||||
}
|
||||
}
|
||||
-- Sort flag = SORT_REGULAR --
|
||||
bool(true)
|
||||
@ -144,15 +144,6 @@ array(3) {
|
||||
int(6)
|
||||
}
|
||||
[1]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(5) "first"
|
||||
[5]=>
|
||||
string(6) "second"
|
||||
[6]=>
|
||||
string(5) "third"
|
||||
}
|
||||
[2]=>
|
||||
array(3) {
|
||||
["a"]=>
|
||||
string(6) "orange"
|
||||
@ -161,6 +152,15 @@ array(3) {
|
||||
["c"]=>
|
||||
string(5) "apple"
|
||||
}
|
||||
[2]=>
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(5) "first"
|
||||
[5]=>
|
||||
string(6) "second"
|
||||
[6]=>
|
||||
string(5) "third"
|
||||
}
|
||||
}
|
||||
|
||||
-- Iteration 3 --
|
||||
@ -256,4 +256,4 @@ array(4) {
|
||||
[3]=>
|
||||
int(1)
|
||||
}
|
||||
Done
|
||||
Done
|
||||
|
Binary file not shown.
@ -58,14 +58,14 @@ array(6) {
|
||||
int(1)
|
||||
[1]=>
|
||||
int(1)
|
||||
[3]=>
|
||||
int(2)
|
||||
[2]=>
|
||||
int(2)
|
||||
[5]=>
|
||||
int(3)
|
||||
[3]=>
|
||||
int(2)
|
||||
[4]=>
|
||||
int(3)
|
||||
[5]=>
|
||||
int(3)
|
||||
}
|
||||
-- Numeric array with decreasing values --
|
||||
bool(true)
|
||||
@ -74,22 +74,22 @@ array(6) {
|
||||
int(1)
|
||||
[5]=>
|
||||
int(1)
|
||||
[3]=>
|
||||
int(2)
|
||||
[2]=>
|
||||
int(2)
|
||||
[1]=>
|
||||
int(3)
|
||||
[3]=>
|
||||
int(2)
|
||||
[0]=>
|
||||
int(3)
|
||||
[1]=>
|
||||
int(3)
|
||||
}
|
||||
-- Numeric array with increasing and decreasing values --
|
||||
bool(true)
|
||||
array(6) {
|
||||
[5]=>
|
||||
int(1)
|
||||
[0]=>
|
||||
int(1)
|
||||
[5]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(2)
|
||||
[4]=>
|
||||
|
@ -123,32 +123,32 @@ echo "Done"
|
||||
-- Testing uasort() with StaticClass objects --
|
||||
bool(true)
|
||||
array(4) {
|
||||
[3]=>
|
||||
object(StaticClass)#%d (0) {
|
||||
}
|
||||
[2]=>
|
||||
[0]=>
|
||||
object(StaticClass)#%d (0) {
|
||||
}
|
||||
[1]=>
|
||||
object(StaticClass)#%d (0) {
|
||||
}
|
||||
[0]=>
|
||||
[2]=>
|
||||
object(StaticClass)#%d (0) {
|
||||
}
|
||||
[3]=>
|
||||
object(StaticClass)#%d (0) {
|
||||
}
|
||||
}
|
||||
-- Testing uasort() with EmptyClass objects --
|
||||
bool(true)
|
||||
array(4) {
|
||||
[3]=>
|
||||
object(EmptyClass)#%d (0) {
|
||||
}
|
||||
[2]=>
|
||||
[0]=>
|
||||
object(EmptyClass)#%d (0) {
|
||||
}
|
||||
[1]=>
|
||||
object(EmptyClass)#%d (0) {
|
||||
}
|
||||
[0]=>
|
||||
[2]=>
|
||||
object(EmptyClass)#%d (0) {
|
||||
}
|
||||
[3]=>
|
||||
object(EmptyClass)#%d (0) {
|
||||
}
|
||||
}
|
||||
|
@ -56,10 +56,10 @@ array(7) {
|
||||
int(1)
|
||||
[5]=>
|
||||
int(2)
|
||||
["z"]=>
|
||||
int(3)
|
||||
[3]=>
|
||||
int(3)
|
||||
["z"]=>
|
||||
int(3)
|
||||
["o"]=>
|
||||
int(6)
|
||||
["a"]=>
|
||||
|
@ -62,16 +62,16 @@ array(8) {
|
||||
[0]=>
|
||||
int(-1)
|
||||
}
|
||||
[6]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
}
|
||||
[3]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(0)
|
||||
}
|
||||
[6]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
}
|
||||
[1]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
|
@ -72,12 +72,12 @@ array(8) {
|
||||
[2]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
int(0)
|
||||
}
|
||||
[3]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(0)
|
||||
string(0) ""
|
||||
}
|
||||
[4]=>
|
||||
array(1) {
|
||||
|
@ -239,11 +239,11 @@ array(5) {
|
||||
}
|
||||
-- with table = HTML_SPECIALCHARS, ENT_NOQUOTES --
|
||||
array(3) {
|
||||
[">"]=>
|
||||
string(4) ">"
|
||||
["<"]=>
|
||||
string(4) "<"
|
||||
["&"]=>
|
||||
string(5) "&"
|
||||
["<"]=>
|
||||
string(4) "<"
|
||||
[">"]=>
|
||||
string(4) ">"
|
||||
}
|
||||
Done
|
||||
|
@ -33,7 +33,7 @@
|
||||
|
||||
#include "php_version.h"
|
||||
#include "zend.h"
|
||||
#include "zend_qsort.h"
|
||||
#include "zend_sort.h"
|
||||
#include "php_compat.h"
|
||||
|
||||
#include "zend_API.h"
|
||||
|
@ -243,7 +243,7 @@ static void print_modules(void)
|
||||
|
||||
zend_hash_init(&sorted_registry, 64, NULL, NULL, 1);
|
||||
zend_hash_copy(&sorted_registry, &module_registry, NULL);
|
||||
zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0);
|
||||
zend_hash_sort(&sorted_registry, module_name_cmp, 0);
|
||||
zend_hash_apply(&sorted_registry, print_module_info);
|
||||
zend_hash_destroy(&sorted_registry);
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ static void print_modules(void) /* {{{ */
|
||||
|
||||
zend_hash_init(&sorted_registry, 50, NULL, NULL, 0);
|
||||
zend_hash_copy(&sorted_registry, &module_registry, NULL);
|
||||
zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0);
|
||||
zend_hash_sort(&sorted_registry, module_name_cmp, 0);
|
||||
zend_hash_apply(&sorted_registry, print_module_info);
|
||||
zend_hash_destroy(&sorted_registry);
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ static void print_modules(void)
|
||||
|
||||
zend_hash_init(&sorted_registry, 50, NULL, NULL, 1);
|
||||
zend_hash_copy(&sorted_registry, &module_registry, NULL);
|
||||
zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0);
|
||||
zend_hash_sort(&sorted_registry, module_name_cmp, 0);
|
||||
zend_hash_apply(&sorted_registry, print_module_info);
|
||||
zend_hash_destroy(&sorted_registry);
|
||||
}
|
||||
|
@ -76,8 +76,8 @@ static void phpdbg_array_intersect_init(phpdbg_intersect_ptr *info, HashTable *h
|
||||
info->ht[0] = ht1;
|
||||
info->ht[1] = ht2;
|
||||
|
||||
zend_hash_sort(info->ht[0], zend_qsort, (compare_func_t) phpdbg_array_data_compare, 0);
|
||||
zend_hash_sort(info->ht[1], zend_qsort, (compare_func_t) phpdbg_array_data_compare, 0);
|
||||
zend_hash_sort(info->ht[0], (compare_func_t) phpdbg_array_data_compare, 0);
|
||||
zend_hash_sort(info->ht[1], (compare_func_t) phpdbg_array_data_compare, 0);
|
||||
|
||||
zend_hash_internal_pointer_reset_ex(info->ht[0], &info->pos[0]);
|
||||
zend_hash_internal_pointer_reset_ex(info->ht[1], &info->pos[1]);
|
||||
|
@ -132,7 +132,7 @@ ADD_SOURCES("Zend", "zend_language_parser.c zend_language_scanner.c \
|
||||
zend_llist.c zend_vm_opcodes.c zend_opcode.c zend_operators.c zend_ptr_stack.c \
|
||||
zend_stack.c zend_variables.c zend.c zend_API.c zend_extensions.c \
|
||||
zend_hash.c zend_list.c zend_indent.c zend_builtin_functions.c \
|
||||
zend_sprintf.c zend_ini.c zend_qsort.c zend_multibyte.c zend_ts_hash.c \
|
||||
zend_sprintf.c zend_ini.c zend_sort.c zend_multibyte.c zend_ts_hash.c \
|
||||
zend_stream.c zend_iterators.c zend_interfaces.c zend_objects.c \
|
||||
zend_object_handlers.c zend_objects_API.c \
|
||||
zend_default_classes.c zend_execute.c zend_strtod.c zend_gc.c zend_closures.c \
|
||||
|
Loading…
Reference in New Issue
Block a user