From 16037cfc6f4052f781f71ce77078a89b81249b28 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 11 May 2011 14:02:04 +0000 Subject: [PATCH] 2011-05-11 16:01 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbapi.h * harbour/src/vm/hashes.c + add new public C function: HB_BOOL hb_hashClear( PHB_ITEM pHash ) * do not generate RTE when unexisting key is passed to HB_HDEL() now code which makes sth like: if xKey $ hValue hb_hDel( hValue, xKey ) endif can be reduced to: hb_hDel( hValue, xKey ) * harbour/src/vm/hashfunc.c + added new PRG function: HB_HCLEAR( ) -> --- harbour/ChangeLog | 15 +++++++++++++++ harbour/include/hbapi.h | 1 + harbour/src/vm/hashes.c | 2 +- harbour/src/vm/hashfunc.c | 19 +++++++++++++++---- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index ac6c64b839..14c52df4a2 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,21 @@ The license applies to all entries newer than 2009-04-28. */ +2011-05-11 16:01 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbapi.h + * harbour/src/vm/hashes.c + + add new public C function: HB_BOOL hb_hashClear( PHB_ITEM pHash ) + * do not generate RTE when unexisting key is passed to HB_HDEL() + now code which makes sth like: + if xKey $ hValue + hb_hDel( hValue, xKey ) + endif + can be reduced to: + hb_hDel( hValue, xKey ) + + * harbour/src/vm/hashfunc.c + + added new PRG function: HB_HCLEAR( ) -> + 2011-05-11 06:55 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbxbp/xbpmenubar.prg ! Changed: XbpMenubar():visible := FALSE to TRUE. diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 11967dd22c..c1c4381985 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -864,6 +864,7 @@ extern HB_EXPORT HB_BOOL hb_hashDel( PHB_ITEM pHash, PHB_ITEM pKey ); extern HB_EXPORT HB_BOOL hb_hashAdd( PHB_ITEM pHash, PHB_ITEM pKey, PHB_ITEM pValue ); extern HB_EXPORT HB_BOOL hb_hashAddNew( PHB_ITEM pHash, PHB_ITEM pKey, PHB_ITEM pValue ); extern HB_EXPORT HB_BOOL hb_hashRemove( PHB_ITEM pHash, PHB_ITEM pItem ); +extern HB_EXPORT HB_BOOL hb_hashClear( PHB_ITEM pHash ); extern HB_EXPORT HB_BOOL hb_hashAllocNewPair( PHB_ITEM pHash, PHB_ITEM * pKeyPtr, PHB_ITEM * pValPtr ); extern HB_EXPORT void hb_hashSort( PHB_ITEM pHash ); extern HB_EXPORT PHB_ITEM hb_hashClone( PHB_ITEM pHash ); diff --git a/harbour/src/vm/hashes.c b/harbour/src/vm/hashes.c index 956976a769..d8398693b7 100644 --- a/harbour/src/vm/hashes.c +++ b/harbour/src/vm/hashes.c @@ -682,7 +682,7 @@ HB_BOOL hb_hashScan( PHB_ITEM pHash, PHB_ITEM pKey, HB_SIZE * pnPos ) return HB_FALSE; } -static HB_BOOL hb_hashClear( PHB_ITEM pHash ) +HB_BOOL hb_hashClear( PHB_ITEM pHash ) { HB_TRACE(HB_TR_DEBUG, ("hb_hashClear(%p)", pHash)); diff --git a/harbour/src/vm/hashfunc.c b/harbour/src/vm/hashfunc.c index 6b53c5c5ad..55c9250455 100644 --- a/harbour/src/vm/hashfunc.c +++ b/harbour/src/vm/hashfunc.c @@ -169,10 +169,8 @@ HB_FUNC( HB_HDEL ) if( pHash && pKey ) { - if( hb_hashDel( pHash, pKey ) ) - hb_itemReturn( pHash ); - else - hb_errRT_BASE( EG_BOUND, 1133, NULL, hb_langDGetErrorDesc( EG_ARRASSIGN ), 2, pHash, pKey ); + hb_hashDel( pHash, pKey ); + hb_itemReturn( pHash ); } else hb_errRT_BASE( EG_ARG, 1123, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); @@ -289,6 +287,19 @@ HB_FUNC( HB_HVALUES ) hb_errRT_BASE( EG_ARG, 1123, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); } +HB_FUNC( HB_HCLEAR ) +{ + PHB_ITEM pHash = hb_param( 1, HB_IT_HASH ); + + if( pHash ) + { + hb_hashClear( pHash ); + hb_itemReturn( pHash ); + } + else + hb_errRT_BASE( EG_ARG, 1123, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS ); +} + HB_FUNC( HB_HFILL ) { PHB_ITEM pHash = hb_param( 1, HB_IT_HASH );