Some changes for speed.
This commit is contained in:
@@ -8,6 +8,12 @@
|
||||
2002-12-01 23:12 UTC+0100 Foo Bar <foo.bar@foobar.org>
|
||||
*/
|
||||
|
||||
2003-07-14 13:50 UTC-0300 Antonio Carlos Pantaglione <toninho@fwi.com.br>
|
||||
* contrib/rdd_ads/ads1.c
|
||||
* contrib/rdd_ads/adsfunc.c
|
||||
! Changes in adsGetValue and AdsKeyCount() for speed(). Tested with
|
||||
ADS Local 6.2, not tested with prior versions of ADS.
|
||||
|
||||
2003-07-14 14:39 UTC+0100 Antonio Linares <alinares@fivetechsoft.com>
|
||||
* source/vm/classes.c
|
||||
+ HB_SETCLSHANDLE() implemented
|
||||
|
||||
@@ -1085,48 +1085,46 @@ static ERRCODE adsGetValue( ADSAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
|
||||
{
|
||||
LPFIELD pField;
|
||||
BYTE * pBuffer = pArea->pRecord;
|
||||
UNSIGNED8 szName[ ADS_MAX_FIELD_NAME ];
|
||||
/* For fast stack allocations, we use the largest possible
|
||||
sized buffer. Even though 128 bytes is overkill for 10 byte
|
||||
ADSCDX access, the speed over hb_xgrab(pArea->uiMaxFieldNameLength+1)
|
||||
seems worth it. */
|
||||
|
||||
UNSIGNED16 pusBufLen = ADS_MAX_FIELD_NAME + 1;
|
||||
UNSIGNED32 pulLength;
|
||||
DOUBLE dVal;
|
||||
DOUBLE dVal = 0;
|
||||
|
||||
HB_TRACE(HB_TR_DEBUG, ("adsGetValue(%p, %hu, %p)", pArea, uiIndex, pItem));
|
||||
|
||||
dVal = 0;
|
||||
|
||||
if( uiIndex > pArea->uiFieldCount )
|
||||
return FAILURE;
|
||||
|
||||
pField = pArea->lpFields + uiIndex - 1;
|
||||
|
||||
/* Cannot test for EOF here because related children may not have the eof flag reset yet, yielded erroneous blank results */
|
||||
|
||||
AdsGetFieldName( pArea->hTable, uiIndex, szName, &pusBufLen );
|
||||
// This code was optimized for use ADSFIELD() macro instead
|
||||
// AdsGetFieldName() function for speed. Toninho@fwi, 14/07/2003
|
||||
|
||||
switch( pField->uiType )
|
||||
{
|
||||
case HB_IT_STRING:
|
||||
pulLength = pArea->maxFieldLen;
|
||||
if (AdsGetField( pArea->hTable, szName, pBuffer, &pulLength, ADS_NONE ) == AE_NO_CURRENT_RECORD )
|
||||
{
|
||||
memset( pBuffer, ' ', pField->uiLen );
|
||||
pArea->fEof = TRUE;
|
||||
}
|
||||
pulLength = pArea->maxFieldLen;
|
||||
if( AdsGetField( pArea->hTable, ADSFIELD( uiIndex ), pBuffer, &pulLength, ADS_NONE ) == AE_NO_CURRENT_RECORD )
|
||||
{
|
||||
memset( pBuffer, ' ', pField->uiLen );
|
||||
pArea->fEof = TRUE;
|
||||
}
|
||||
hb_itemPutCL( pItem, ( char * ) pBuffer, pField->uiLen );
|
||||
break;
|
||||
|
||||
case HB_IT_LONG:
|
||||
pulLength = pArea->maxFieldLen + 1;
|
||||
if (AdsGetField( pArea->hTable, szName, pBuffer, &pulLength, ADS_NONE ) == AE_NO_CURRENT_RECORD )
|
||||
if( AdsGetField( pArea->hTable, ADSFIELD( uiIndex ), pBuffer, &pulLength, ADS_NONE ) == AE_NO_CURRENT_RECORD )
|
||||
{
|
||||
memset( pBuffer, ' ', pField->uiLen );
|
||||
pArea->fEof = TRUE;
|
||||
}
|
||||
AdsGetDouble(pArea->hTable, szName, &dVal);
|
||||
AdsGetDouble(pArea->hTable, ADSFIELD( uiIndex ), &dVal);
|
||||
if( pField->uiDec ) {
|
||||
hb_itemPutNDLen( pItem, dVal,
|
||||
( int ) pField->uiLen - ( ( int ) pField->uiDec + 1 ),
|
||||
@@ -1139,7 +1137,7 @@ static ERRCODE adsGetValue( ADSAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
|
||||
case ADS_DOUBLE :
|
||||
hb_itemPutNDLen( pItem, dVal,
|
||||
( int ) pField->uiLen,
|
||||
( int ) pField->uiDec /*hb_set.HB_SET_DECIMALS*/ );
|
||||
( int ) pField->uiDec );
|
||||
|
||||
break;
|
||||
/*case ADS_AUTOINC:
|
||||
@@ -1159,7 +1157,7 @@ static ERRCODE adsGetValue( ADSAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
|
||||
AdsGetDateFormat ( pucFormat, &pusLen );
|
||||
AdsSetDateFormat ( (UNSIGNED8*)"YYYYMMDD" );
|
||||
pulLength = pArea->maxFieldLen + 1;
|
||||
if (AdsGetField( pArea->hTable, szName, pBuffer, &pulLength, ADS_NONE ) == AE_NO_CURRENT_RECORD )
|
||||
if (AdsGetField( pArea->hTable, ADSFIELD( uiIndex ), pBuffer, &pulLength, ADS_NONE ) == AE_NO_CURRENT_RECORD )
|
||||
{
|
||||
memset( pBuffer, ' ', pField->uiLen );
|
||||
pArea->fEof = TRUE;
|
||||
@@ -1172,7 +1170,7 @@ static ERRCODE adsGetValue( ADSAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
|
||||
case HB_IT_LOGICAL:
|
||||
{
|
||||
UNSIGNED16 pbValue = FALSE;
|
||||
if (AdsGetLogical( pArea->hTable, szName, &pbValue ) == AE_NO_CURRENT_RECORD )
|
||||
if (AdsGetLogical( pArea->hTable, ADSFIELD( uiIndex ), &pbValue ) == AE_NO_CURRENT_RECORD )
|
||||
{
|
||||
pbValue = FALSE;
|
||||
pArea->fEof = TRUE;
|
||||
@@ -1186,7 +1184,7 @@ static ERRCODE adsGetValue( ADSAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
|
||||
UNSIGNED8 *pucBuf;
|
||||
UNSIGNED32 pulLen;
|
||||
|
||||
if ( AdsGetMemoLength( pArea->hTable, szName, &pulLen ) == AE_NO_CURRENT_RECORD )
|
||||
if ( AdsGetMemoLength( pArea->hTable, ADSFIELD( uiIndex ), &pulLen ) == AE_NO_CURRENT_RECORD )
|
||||
hb_itemPutC( pItem, "" );
|
||||
else
|
||||
{
|
||||
@@ -1194,7 +1192,7 @@ static ERRCODE adsGetValue( ADSAREAP pArea, USHORT uiIndex, PHB_ITEM pItem )
|
||||
{
|
||||
pulLen++; /* make room for NULL */
|
||||
pucBuf = (UNSIGNED8*) hb_xgrab( pulLen );
|
||||
AdsGetString( pArea->hTable, szName, pucBuf, &pulLen, ADS_NONE );
|
||||
AdsGetString( pArea->hTable, ADSFIELD( uiIndex ), pucBuf, &pulLen, ADS_NONE );
|
||||
hb_itemPutCL( pItem, ( char * ) pucBuf, pulLen );
|
||||
hb_xfree( pucBuf );
|
||||
}
|
||||
|
||||
@@ -391,13 +391,14 @@ HB_FUNC( ADSKEYNO )
|
||||
|
||||
HB_FUNC( ADSKEYCOUNT )
|
||||
{
|
||||
ADSAREAP pArea;
|
||||
ADSAREAP pArea;
|
||||
UNSIGNED8* ordName;
|
||||
UNSIGNED8 ordNum;
|
||||
UNSIGNED8 ordNum;
|
||||
UNSIGNED32 pulKey;
|
||||
ADSHANDLE hIndex;
|
||||
ADSHANDLE hIndex;
|
||||
UNSIGNED16 usFilterOption = ADS_IGNOREFILTERS;
|
||||
UNSIGNED8 pucScope[ ADS_MAX_KEY_LENGTH+1 ];
|
||||
UNSIGNED8 pucScope[ ADS_MAX_KEY_LENGTH+1 ];
|
||||
UNSIGNED8 pucFilter[HARBOUR_MAX_RDD_FILTER_LENGTH+1];
|
||||
UNSIGNED16 pusBufLen = ADS_MAX_KEY_LENGTH+1;
|
||||
|
||||
pArea = (ADSAREAP) hb_rddGetCurrentWorkAreaPointer();
|
||||
@@ -435,24 +436,32 @@ HB_FUNC( ADSKEYCOUNT )
|
||||
|
||||
pulKey = 0L;
|
||||
if ( usFilterOption == ADS_IGNOREFILTERS )
|
||||
AdsGetRecordCount ( hIndex, usFilterOption, &pulKey);
|
||||
AdsGetRecordCount( hIndex, ADS_IGNOREFILTERS, &pulKey );
|
||||
else /* ads scope handling is flawed; do our own */
|
||||
{ /* One more optimization would be to check if there's a fully optimized AOF available so don't walk ours */
|
||||
AdsGetScope ( hIndex, ADS_BOTTOM, pucScope, &pusBufLen);
|
||||
if ( pusBufLen ) /* had a scope, walk it. Skips obey filters */
|
||||
if ( pusBufLen ) // had a scope
|
||||
{
|
||||
AdsGetRecordNum( pArea->hTable, ADS_IGNOREFILTERS,
|
||||
(UNSIGNED32 *)&(pArea->ulRecNo) );
|
||||
AdsGotoTop ( hIndex );
|
||||
AdsAtEOF( pArea->hTable, (UNSIGNED16 *)&(pArea->fEof) );
|
||||
|
||||
while ( AdsSkip ( hIndex, 1 ) != AE_NO_CURRENT_RECORD && !pArea->fEof )
|
||||
AdsGetAOF( pArea->hTable, pucFilter, &pusBufLen );
|
||||
if ( !pusBufLen ) // had a AOF
|
||||
AdsGetFilter( pArea->hTable, pucFilter, &pusBufLen );
|
||||
if ( pusBufLen ) // had a scope with AOF or filter, walk it. Skips obey filters */
|
||||
{
|
||||
AdsGetRecordNum( pArea->hTable, ADS_IGNOREFILTERS,
|
||||
(UNSIGNED32 *)&(pArea->ulRecNo) );
|
||||
AdsGotoTop ( hIndex );
|
||||
AdsAtEOF( pArea->hTable, (UNSIGNED16 *)&(pArea->fEof) );
|
||||
|
||||
while ( AdsSkip ( hIndex, 1 ) != AE_NO_CURRENT_RECORD && !pArea->fEof )
|
||||
{
|
||||
AdsAtEOF( pArea->hTable, (UNSIGNED16 *)&(pArea->fEof) );
|
||||
pulKey++;
|
||||
}
|
||||
AdsGotoRecord( pArea->hTable, pArea->ulRecNo );
|
||||
AdsAtEOF( pArea->hTable, (UNSIGNED16 *)&(pArea->fEof) );
|
||||
pulKey++;
|
||||
}
|
||||
AdsGotoRecord( pArea->hTable, pArea->ulRecNo );
|
||||
AdsAtEOF( pArea->hTable, (UNSIGNED16 *)&(pArea->fEof) );
|
||||
else
|
||||
AdsGetRecordCount( hIndex, usFilterOption, &pulKey );
|
||||
}
|
||||
else /* no scope set */
|
||||
AdsGetRecordCount ( hIndex, usFilterOption, &pulKey);
|
||||
|
||||
Reference in New Issue
Block a user