From 3713e7046e967fea1404a4c7d035567cee81aeca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Czerpak?= Date: Thu, 23 May 2013 18:16:04 +0200 Subject: [PATCH] 2013-05-23 18:16 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * include/hbapi.h * src/vm/hvm.c * keep natural internal order in newly created hashes --- ChangeLog.txt | 8 +++++++- include/hbapi.h | 2 +- src/vm/hvm.c | 14 +++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index f6928f6a6f..4a24b020c0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -10,6 +10,11 @@ * Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment */ +2013-05-23 18:16 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) + * include/hbapi.h + * src/vm/hvm.c + * keep natural internal order in newly created hashes + 2013-05-22 14:15 UTC+0300 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt) * contrib/sddpg/core.c ! added missing parentheses in last commit @@ -46,7 +51,8 @@ 2013-05-16 17:00 UTC+0200 Jfl mafact (jfl/at/mafact.com) * contrib/rddads/adsfunc.c - ! Adding 2nd param to function ADSCOPYTABLECONTENT to allow filtering like in ADSCOPYTABLE + ! Adding 2nd param to function ADSCOPYTABLECONTENT to allow filtering + like in ADSCOPYTABLE 2013-05-15 19:54 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) * src/pp/hbpp.c diff --git a/include/hbapi.h b/include/hbapi.h index 4c6f1dcae4..0dc97aa351 100644 --- a/include/hbapi.h +++ b/include/hbapi.h @@ -917,7 +917,7 @@ extern HB_EXPORT HB_BOOL hb_hashDelAt( PHB_ITEM pHash, HB_SIZE nPos ); #define HB_HASH_KEEPORDER 0x40 #define HB_HASH_FLAG_MASK 0xFFFF -#define HB_HASH_FLAG_DEFAULT ( HB_HASH_AUTOADD_ASSIGN | HB_HASH_BINARY ) +#define HB_HASH_FLAG_DEFAULT ( HB_HASH_AUTOADD_ASSIGN | HB_HASH_BINARY | HB_HASH_KEEPORDER ) #define HB_HASH_UNION 0 /* logical OR on items in two hash tables */ #define HB_HASH_INTERSECT 1 /* logical AND on items in two hash tables */ diff --git a/src/vm/hvm.c b/src/vm/hvm.c index 2de31e2792..faf8c1504d 100644 --- a/src/vm/hvm.c +++ b/src/vm/hvm.c @@ -5443,28 +5443,28 @@ static void hb_vmHashGen( HB_SIZE nElements ) /* generates an nElements Hash and { HB_STACK_TLS_PRELOAD PHB_ITEM pHash, pKey, pVal; + int iPos; HB_TRACE( HB_TR_DEBUG, ( "hb_vmHashGen(%" HB_PFS "u)", nElements ) ); /* create new hash item */ pHash = hb_hashNew( NULL ); hb_hashPreallocate( pHash, nElements ); - while( nElements-- ) + nElements <<= 1; + iPos = - ( int ) nElements; + while( iPos ) { - pKey = hb_stackItemFromTop( -2 ); - pVal = hb_stackItemFromTop( -1 ); + pKey = hb_stackItemFromTop( iPos++ ); + pVal = hb_stackItemFromTop( iPos++ ); if( HB_IS_HASHKEY( pKey ) ) - { hb_hashAddNew( pHash, pKey, pVal ); - hb_stackPop(); - hb_stackPop(); - } else { hb_errRT_BASE( EG_BOUND, 1133, NULL, hb_langDGetErrorDesc( EG_ARRASSIGN ), 3, pHash, pKey, pVal ); break; } } + hb_stackRemove( hb_stackTopOffset() - nElements ); hb_itemMove( hb_stackAllocItem(), pHash ); hb_itemRelease( pHash ); }