From 11435cf83ef689cc33dfb160e41c84702452b9f4 Mon Sep 17 00:00:00 2001 From: Ron Pinkas Date: Wed, 18 Apr 2001 06:52:00 +0000 Subject: [PATCH] 2001-04-17 19:30 UTC-0800 Ron Pinkas * include/hbapi.h * Removed 3rd paramater from declaration of hb_arrayClone(). * source/vm/arrays.c ! Optimized and improved hb_arrayClone(). * source/vm/arrayshb.c * source/vm/classes.c * source/vm/hvm.c * Changed calls to hb_arrayClone() to remove no longer needed, 3rd parameter. --- harbour/ChangeLog | 12 ++++ harbour/include/hbapi.h | 4 +- harbour/source/vm/arrays.c | 131 ++++++++++++++++++----------------- harbour/source/vm/arrayshb.c | 2 +- harbour/source/vm/classes.c | 22 +++--- harbour/source/vm/hvm.c | 2 +- 6 files changed, 93 insertions(+), 80 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index c68d219a57..218fcf7073 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,15 @@ +2001-04-17 19:30 UTC-0800 Ron Pinkas + * include/hbapi.h + * Removed 3rd paramater from declaration of hb_arrayClone(). + + * source/vm/arrays.c + ! Optimized and improved hb_arrayClone(). + + * source/vm/arrayshb.c + * source/vm/classes.c + * source/vm/hvm.c + * Changed calls to hb_arrayClone() to remove no longer needed, 3rd parameter. + 2001-04-17 19:30 UTC-0800 Ron Pinkas * include/hbapi.h + Added typedef struct HB_NESTED_CLONED diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index daaef39c4d..4c9094aa36 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -258,7 +258,7 @@ typedef struct _HB_VALUE typedef struct _HB_NESTED_CLONED { - PHB_ITEM pSrc; + PHB_ITEM pSrcItems; PHB_ITEM pDest; struct _HB_NESTED_CLONED * pNext; } HB_NESTED_CLONED, * PHB_NESTED_CLONED; @@ -385,7 +385,7 @@ extern BOOL hb_arrayFill( PHB_ITEM pArray, PHB_ITEM pValue, ULONG * pulStart extern ULONG hb_arrayScan( PHB_ITEM pArray, PHB_ITEM pValue, ULONG * pulStart, ULONG * pulCount ); /* scan an array for a given item, or until code-block item returns TRUE */ extern BOOL hb_arrayEval( PHB_ITEM pArray, PHB_ITEM bBlock, ULONG * pulStart, ULONG * pulCount ); /* execute a code-block for every element of an array item */ extern BOOL hb_arrayCopy( PHB_ITEM pSrcArray, PHB_ITEM pDstArray, ULONG * pulStart, ULONG * pulCount, ULONG * pulTarget ); /* copy items from one array to another */ -extern PHB_ITEM hb_arrayClone( PHB_ITEM pArray, PHB_NESTED_CLONED pClonedList, BOOL *bCyclic ); /* returns a duplicate of an existing array, including all nested items */ +extern PHB_ITEM hb_arrayClone( PHB_ITEM pArray, PHB_NESTED_CLONED pClonedList ); /* returns a duplicate of an existing array, including all nested items */ extern BOOL hb_arraySort( PHB_ITEM pArray, ULONG * pulStart, ULONG * pulCount, PHB_ITEM pBlock ); /* sorts an array item */ extern PHB_ITEM hb_arrayFromStack( USHORT uiLen ); /* Creates and returns an Array of n Elements from the Eval Stack - Does NOT pop the items. */ extern PHB_ITEM hb_arrayFromParams( void ); /* Creates and returns an Array of current Generic Parameters. */ diff --git a/harbour/source/vm/arrays.c b/harbour/source/vm/arrays.c index be9e8cbeb7..ccf7caa5a6 100644 --- a/harbour/source/vm/arrays.c +++ b/harbour/source/vm/arrays.c @@ -700,7 +700,7 @@ BOOL hb_arrayCopy( PHB_ITEM pSrcArray, PHB_ITEM pDstArray, ULONG * pulStart, return FALSE; } -PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray, PHB_NESTED_CLONED pClonedList, BOOL *bCyclic ) +PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray, PHB_NESTED_CLONED pClonedList ) { HB_TRACE(HB_TR_DEBUG, ("hb_arrayClone(%p, %p)", pSrcArray, pClonedList)); @@ -714,49 +714,39 @@ PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray, PHB_NESTED_CLONED pClonedList, BOOL PHB_NESTED_CLONED pCloned; BOOL bTop; - if( pClonedList ) + pDstArray = hb_itemNew( NULL ); + hb_arrayNew( pDstArray, ulSrcLen ); + + if( pClonedList == NULL ) { - bTop = FALSE; + bTop = TRUE; - /* Broken down like this to avoid redandant comparisons. */ + pClonedList = ( PHB_NESTED_CLONED ) hb_xgrab( sizeof( HB_NESTED_CLONED ) ); pCloned = pClonedList; - if( pCloned->pSrc == pSrcArray ) - { - if( bCyclic ) - { - *bCyclic = TRUE; - } - return pCloned->pDest; - } - while( pCloned->pNext ) - { - pCloned = pCloned->pNext; - if( pCloned->pSrc == pSrcArray ) - { - if( bCyclic ) - { - *bCyclic = TRUE; - } - return pCloned->pDest; - } - } - if( pCloned->pSrc == pSrcArray ) - { - if( bCyclic ) - { - *bCyclic = TRUE; - } - return pCloned->pDest; - } + pCloned->pSrcItems = pSrcArray->item.asArray.value->pItems; + pCloned->pDest = pDstArray; + + pCloned->pNext = NULL; } else { - bTop = TRUE; - } + bTop = FALSE; - pDstArray = hb_itemNew( NULL ); - hb_arrayNew( pDstArray, ulSrcLen ); + pCloned = pClonedList; + while( pCloned->pNext ) + { + pCloned = pCloned->pNext; + } + + pCloned->pNext = ( PHB_NESTED_CLONED ) hb_xgrab( sizeof( HB_NESTED_CLONED ) ); + pCloned = pCloned->pNext; + + pCloned->pSrcItems = pSrcArray->item.asArray.value->pItems; + pCloned->pDest = pDstArray; + + pCloned->pNext = NULL; + } pDstBaseArray = pDstArray->item.asArray.value; pDstBaseArray->uiClass = pSrcBaseArray->uiClass; @@ -764,48 +754,38 @@ PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray, PHB_NESTED_CLONED pClonedList, BOOL for( ulCount = 0; ulCount < ulSrcLen; ulCount++ ) { PHB_ITEM pSrcItem = pSrcBaseArray->pItems + ulCount; - BOOL bDontRelease = FALSE; if( pSrcItem->type == HB_IT_ARRAY ) { PHB_ITEM pClone; - if( bTop ) + /* Broken down like this to avoid redandant comparisons. */ + pCloned = pClonedList; + if( pCloned->pSrcItems == pSrcItem->item.asArray.value->pItems ) { - /* Top Level - create an empty list. */ - pClonedList = ( PHB_NESTED_CLONED ) hb_xgrab( sizeof( HB_NESTED_CLONED ) ); - pCloned = pClonedList; + pClone = pCloned->pDest; + goto DontClone; } - else + while( pCloned->pNext ) { - /* pCloned must alreay point to last item in the list (see above). */ - pCloned->pNext = ( PHB_NESTED_CLONED ) hb_xgrab( sizeof( HB_NESTED_CLONED ) ); pCloned = pCloned->pNext; - } - pCloned->pSrc = pSrcArray; - pCloned->pDest = pDstArray; - pCloned->pNext = NULL; - - pClone = hb_arrayClone( pSrcItem, pClonedList, &bDontRelease ); - hb_itemArrayPut( pDstArray, ulCount + 1, pClone ); - - if( ! bDontRelease ) - { - hb_itemRelease( pClone ); - } - - /* Top Level - Release the created list. */ - if( bTop ) - { - while( pClonedList->pNext ) + if( pCloned->pSrcItems == pSrcItem->item.asArray.value->pItems ) { - pCloned = pClonedList; - pClonedList = pClonedList->pNext; - hb_xfree( pCloned ); + pClone = pCloned->pDest; + goto DontClone; } - hb_xfree( pClonedList ); } + if( pCloned->pSrcItems == pSrcItem->item.asArray.value->pItems ) + { + pClone = pCloned->pDest; + goto DontClone; + } + + pClone = hb_arrayClone( pSrcItem, pClonedList ); + + DontClone : + hb_itemArrayPut( pDstArray, ulCount + 1, pClone ); } else { @@ -813,6 +793,27 @@ PHB_ITEM hb_arrayClone( PHB_ITEM pSrcArray, PHB_NESTED_CLONED pClonedList, BOOL } } + /* Top Level - Release the created list. */ + if( bTop ) + { + while( pClonedList->pNext ) + { + pCloned = pClonedList; + pClonedList = pClonedList->pNext; + + if( pCloned->pDest != pDstArray ) + { + hb_itemRelease( pCloned->pDest ); + } + hb_xfree( pCloned ); + } + if( pCloned->pDest != pDstArray ) + { + hb_itemRelease( pClonedList->pDest ); + } + hb_xfree( pClonedList ); + } + return pDstArray; } else diff --git a/harbour/source/vm/arrayshb.c b/harbour/source/vm/arrayshb.c index 6059bc669a..3d183b985c 100644 --- a/harbour/source/vm/arrayshb.c +++ b/harbour/source/vm/arrayshb.c @@ -288,6 +288,6 @@ HB_FUNC( ACLONE ) PHB_ITEM pSrcArray = hb_param( 1, HB_IT_ARRAY ); if( pSrcArray && ! hb_arrayIsObject( pSrcArray ) ) - hb_itemRelease( hb_itemReturn( hb_arrayClone( pSrcArray, NULL, NULL ) ) ); /* AClone() returns the new array */ + hb_itemRelease( hb_itemReturn( hb_arrayClone( pSrcArray, NULL ) ) ); /* AClone() returns the new array */ } diff --git a/harbour/source/vm/classes.c b/harbour/source/vm/classes.c index fac10084fe..deb59397d7 100644 --- a/harbour/source/vm/classes.c +++ b/harbour/source/vm/classes.c @@ -823,7 +823,7 @@ HB_FUNC( __CLSADDMSG ) if( pInit && ! HB_IS_NIL( pInit ) ) /* Initializer found */ { if( HB_IS_ARRAY( pInit ) ) - pNewMeth->pInitValue = hb_arrayClone( pInit, NULL, NULL ); + pNewMeth->pInitValue = hb_arrayClone( pInit, NULL ); else { pNewMeth->pInitValue = hb_itemNew( NULL ); @@ -850,7 +850,7 @@ HB_FUNC( __CLSADDMSG ) if( pInit && ! HB_IS_NIL( pInit ) ) /* Initializer found */ { if( HB_IS_ARRAY( pInit ) ) - pNewMeth->pInitValue = hb_arrayClone( pInit, NULL, NULL ); + pNewMeth->pInitValue = hb_arrayClone( pInit, NULL ); else { pNewMeth->pInitValue = hb_itemNew( NULL ); @@ -994,9 +994,9 @@ HB_FUNC( __CLSNEW ) pNewCls->uiHashKey = pSprCls->uiHashKey; /* CLASS DATA Not Shared ( new array, new value ) */ - pNewCls->pClassDatas = hb_arrayClone( pSprCls->pClassDatas, NULL, NULL ); + pNewCls->pClassDatas = hb_arrayClone( pSprCls->pClassDatas, NULL ); - pNewCls->pInlines = hb_arrayClone( pSprCls->pInlines, NULL, NULL ); + pNewCls->pInlines = hb_arrayClone( pSprCls->pInlines, NULL ); pNewCls->uiDatasShared = pSprCls->uiDatasShared; @@ -1009,7 +1009,7 @@ HB_FUNC( __CLSNEW ) nLenDatas = ( USHORT ) pNewCls->uiDatas; /* ClassDatas */ - pClsAnyTmp = hb_arrayClone( pSprCls->pClassDatas, NULL, NULL ); + pClsAnyTmp = hb_arrayClone( pSprCls->pClassDatas, NULL ); nLen = ( USHORT ) hb_itemSize( pClsAnyTmp ); for( ui = 1; ui <= nLen; ui++ ) { @@ -1024,7 +1024,7 @@ HB_FUNC( __CLSNEW ) pNewCls->uiDatasShared += pSprCls->uiDatasShared; /* Inlines */ - pClsAnyTmp = hb_arrayClone( pSprCls->pInlines, NULL, NULL ); + pClsAnyTmp = hb_arrayClone( pSprCls->pInlines, NULL ); nLen = ( USHORT ) hb_itemSize( pClsAnyTmp ); for( ui = 1; ui <= nLen; ui++ ) { @@ -1122,7 +1122,7 @@ HB_FUNC( __CLSNEW ) PHB_ITEM pInitValue; if( HB_IS_ARRAY( pSprCls->pMethods[ ui ].pInitValue ) ) - pNewCls->pMethods[ uiAt + uiBucket ].pInitValue = hb_arrayClone( pSprCls->pMethods[ ui ].pInitValue, NULL, NULL ); + pNewCls->pMethods[ uiAt + uiBucket ].pInitValue = hb_arrayClone( pSprCls->pMethods[ ui ].pInitValue, NULL ); else { pInitValue = hb_itemNew( NULL ); @@ -1353,7 +1353,7 @@ static PHB_ITEM hb_clsInst( USHORT uiClass, PHB_ITEM * * ppObjects, USHORT * pui { if( HB_IS_ARRAY( pMeth->pInitValue ) ) - pInit = hb_arrayClone( pMeth->pInitValue, NULL, NULL ); + pInit = hb_arrayClone( pMeth->pInitValue, NULL ); else { pInit = hb_itemNew( NULL ); @@ -1414,7 +1414,7 @@ static PHB_ITEM hb_clsInst( USHORT uiClass, PHB_ITEM * * ppObjects, USHORT * pui if( HB_IS_ARRAY( pMeth->pInitValue ) ) { - pInitValue = hb_arrayClone( pMeth->pInitValue, NULL, NULL ); + pInitValue = hb_arrayClone( pMeth->pInitValue, NULL ); } else { @@ -1439,7 +1439,7 @@ static PHB_ITEM hb_clsInst( USHORT uiClass, PHB_ITEM * * ppObjects, USHORT * pui { if( HB_IS_ARRAY( pMeth->pInitValue ) ) - pInit = hb_arrayClone( pMeth->pInitValue, NULL, NULL ); + pInit = hb_arrayClone( pMeth->pInitValue, NULL ); else { pInit = hb_itemNew( NULL ); @@ -1571,7 +1571,7 @@ HB_FUNC( __OBJCLONE ) PHB_ITEM pSrcObject = hb_param( 1, HB_IT_OBJECT ); if( pSrcObject ) - hb_itemRelease( hb_itemReturn( hb_arrayClone( pSrcObject, NULL, NULL ) ) ); + hb_itemRelease( hb_itemReturn( hb_arrayClone( pSrcObject, NULL ) ) ); else hb_errRT_BASE( EG_ARG, 3001, NULL, "__OBJCLONE", 0 ); } diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index 2ca8f17eb3..5211fc61f1 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -4300,7 +4300,7 @@ void hb_vmRequestCancel( void ) * $End$ */ HB_FUNC( __VMVARSLIST ) { - PHB_ITEM pStatics = hb_arrayClone( &s_aStatics, NULL, NULL ); + PHB_ITEM pStatics = hb_arrayClone( &s_aStatics, NULL ); hb_itemCopy( &hb_stack.Return, pStatics ); hb_itemRelease( pStatics );