cvs: php4 /ext/standard array.c
| From: | Stig Venaas | Date: | Tue, 18 Jun 2002 19:38:00 +0000 |
| Subject: | cvs: php4 /ext/standard array.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-12412@lists.php.net to get a copy of this message | ||
venaas Tue Jun 18 15:38:00 2002 EDT
Modified files:
/php4/ext/standard array.c
Log:
Made array_unique() always keep the first occurrences of duplicates,
making the behavior easier to understand, and maybe more useful.
Index: php4/ext/standard/array.c
diff -u php4/ext/standard/array.c:1.167 php4/ext/standard/array.c:1.168
--- php4/ext/standard/array.c:1.167 Tue Jun 18 09:16:33 2002
+++ php4/ext/standard/array.c Tue Jun 18 15:37:59 2002
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.167 2002/06/18 13:16:33 jan Exp $ */
+/* $Id: array.c,v 1.168 2002/06/18 19:37:59 venaas Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -2418,9 +2418,13 @@
{
zval **array;
HashTable *target_hash;
- Bucket **arTmp, **cmpdata, **lastkept;
Bucket *p;
- int i;
+ struct bucketindex {
+ Bucket *b;
+ unsigned int i;
+ };
+ struct bucketindex *arTmp, *cmpdata, *lastkept;
+ unsigned int i;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) {
WRONG_PARAM_COUNT;
@@ -2439,22 +2443,29 @@
return;
/* create and sort array with pointers to the target_hash buckets */
- arTmp = (Bucket **) pemalloc((target_hash->nNumOfElements + 1) * sizeof(Bucket *),
target_hash->persistent);
+ arTmp = (struct bucketindex *) pemalloc((target_hash->nNumOfElements + 1) * sizeof(struct
bucketindex), target_hash->persistent);
if (!arTmp)
RETURN_FALSE;
- for (i = 0, p = target_hash->pListHead; p; i++, p = p->pListNext)
- arTmp[i] = p;
- arTmp[i] = NULL;
+ for (i = 0, p = target_hash->pListHead; p; i++, p = p->pListNext) {
+ arTmp[i].b = p;
+ arTmp[i].i = i;
+ }
+ arTmp[i].b = NULL;
set_compare_func(SORT_STRING TSRMLS_CC);
- zend_qsort((void *) arTmp, i, sizeof(Bucket *), array_data_compare TSRMLS_CC);
+ zend_qsort((void *) arTmp, i, sizeof(struct bucketindex), array_data_compare TSRMLS_CC);
/* go through the sorted array and delete duplicates from the copy */
lastkept = arTmp;
- for (cmpdata = arTmp + 1; *cmpdata; cmpdata++) {
+ for (cmpdata = arTmp + 1; cmpdata->b; cmpdata++) {
if (array_data_compare(lastkept, cmpdata TSRMLS_CC)) {
lastkept = cmpdata;
} else {
- p = *cmpdata;
+ if (lastkept->i > cmpdata->i) {
+ p = lastkept->b;
+ lastkept = cmpdata;
+ } else {
+ p = cmpdata->b;
+ }
if (p->nKeyLength)
zend_hash_del(Z_ARRVAL_P(return_value), p->arKey, p->nKeyLength);
else