Hi,

There is one trick which can be used to optimize your code.
Instead of allocating new item hb_itemNew() and releasing them by
hb_itemRelease() you can use item on HVM stack.
Just simply add at the beginning of your function:
   pKey = hb_stackAllocItem();

You can release it before return by hb_stackPop() but you can also leave
this job to HVM. It will make it automatically restoring function frame.

best regards,
Przemek

On Sun, 07 Jun 2009, Mindaugas Kavaliauskas wrote:
[...]
> #include "hbapi.h"
> #include "hbapiitm.h"
> #include "hbapierr.h"
> #include "hbapilng.h"
> #include "hbvm.h"
> #include "hbstack.h"
>
> static PHB_DYNS s_pDyns_hash = NULL;
>
> HB_FUNC( HASHOBJECT_ONERROR )
> {
>    const char*  szMethod;
>    int          i, iPCount;
>    PHB_ITEM     pSelf, pHash, pValue, pKey;
>
>    iPCount = hb_pcount();
>    pSelf = hb_stackSelfItem();
>    szMethod = hb_itemGetSymbol( hb_stackBaseItem() )->szName;
>
>    if( ! s_pDyns_hash )
>    {
>       s_pDyns_hash = hb_dynsymGetCase( "__HASH" );
>    }
>
>    hb_vmPushDynSym( s_pDyns_hash );
>    hb_vmPush( hb_stackSelfItem() );
>    hb_vmSend( 0 );
>
>    pHash = hb_param( -1, HB_IT_HASH );
>    if( ! pHash )
>    {
>       hb_errRT_BASE( EG_ARG, 2017, NULL, HB_ERR_FUNCNAME, 
> HB_ERR_ARGS_BASEPARAMS );
>       return;
>    }
>
>    if( iPCount == 1 && szMethod[ 0 ] == '_' )
>    {
>       pKey = hb_itemPutCConst( NULL, szMethod + 1 );
>       pValue = hb_param( 1, HB_IT_ANY );
>       hb_hashAdd( pHash, pKey, pValue );
>       hb_itemRelease( pKey );
>       hb_itemReturn( pValue );
>       return;
>    }
>
>    pKey = hb_itemPutCConst( NULL, szMethod );
>    pValue = hb_hashGetItemPtr( pHash, pKey, 0 );
>    if( pValue )
>    {
>       if( HB_IS_SYMBOL( pValue ) )
>       {
>          hb_vmPush( pValue );
>          hb_vmPush( pSelf );
>          for( i = 1; i <= iPCount; i++ )
>          {
>             hb_vmPush( hb_stackItemFromBase( i ) );
>          }
>          hb_vmProc( ( USHORT ) iPCount );
>       }
>       else
>       {
>          hb_itemReturn( pValue );
>       }
>    }
>    else
>    {
>       hb_errRT_BASE( EG_BOUND, 1132, NULL, hb_langDGetErrorDesc( EG_ARRACCESS 
> ), 2, pHash, pKey );
>    }
>    hb_itemRelease( pKey );
> }
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour

Reply via email to