|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-08-05 01:21 UTC] adam at trachtenberg dot com
sort() reindexes arrays of length > 1 at 0, but doesn't do
this for 1 element arrays. The following patch, fixes this
minor inconsistancy. Please review it carefully, my C is
rusty and I don't normally play with these files. It does
build and seem to run correctly for me, with limited testing.
-adam
Here is an example:
$array = array(2 => 'foo', 'bar');
sort($array);
print_r($array);
Array
(
[0] => bar
[1] => foo
)
But,
$array = array(2 => 'foo');
sort($array);
print_r($array);
Array
(
[2] => foo
)
--- zend_hash.c Sun Aug 5 01:17:22 2001
+++ /home/adam/zend_hash.c Sun Aug 5 00:54:21 2001
@@ -1097,6 +1097,13 @@
IS_CONSISTENT(ht);
if (ht->nNumOfElements <= 1) { /* Doesn't require sorting */
+
if (ht->nNumOfElements == 1 && renumber) { /* Renumber 1
element arrays to O */
+
p = ht->pListHead;
+
p->nKeyLength = 0;
+
p->h = 0;
+
ht->nNextFreeElement = 1;
+
zend_hash_rehash(ht);
+
}
return SUCCESS;
}
arTmp = (Bucket **) pemalloc(ht->nNumOfElements *
sizeof(Bucket *), ht->persistent);
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 15:00:01 2025 UTC |
Okay. I will propose a slightly less complicated patch: Index: zend_hash.c =================================================================== RCS file: /repository/Zend/zend_hash.c,v retrieving revision 1.86 diff -u -u -r1.86 zend_hash.c --- zend_hash.c 1 Aug 2002 16:03:21 -0000 1.86 +++ zend_hash.c 17 Aug 2002 06:38:14 -0000 @@ -1115,7 +1115,7 @@ IS_CONSISTENT(ht); - if (ht->nNumOfElements <= 1) { /* Doesn't require sorting */ + if (ht->nNumOfElements < 1) { /* Doesn't require sorting */ return SUCCESS; } arTmp = (Bucket **) pemalloc(ht->nNumOfElements * sizeof(Bucket *), ht->persistent);