2007-06-04 20:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)

* harbour/include/hbexprb.c
  * harbour/include/hbexprop.h
  * harbour/source/common/expropt2.c
    % added compile time optimization for CTOD("")
    % added compile time optimization for - used forconstant string values,
      f.e.:
         ? "Harbour   " - " Compiler"

  * harbour/source/vm/hvm.c
    % added optimization for string resizing in cVal1 - cVal2

  * harbour/source/rtl/dateshb.c
    % minor optimization - removed one not necessary ISCHAR()
This commit is contained in:
Przemyslaw Czerpak
2007-06-04 18:11:04 +00:00
parent c8c4a3986e
commit 973468286a
6 changed files with 151 additions and 18 deletions

View File

@@ -8,6 +8,21 @@
2002-12-01 13:30 UTC+0100 Foo Bar <foo.bar@foobar.org>
*/
2007-06-04 20:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl)
* harbour/include/hbexprb.c
* harbour/include/hbexprop.h
* harbour/source/common/expropt2.c
% added compile time optimization for CTOD("")
% added compile time optimization for - used forconstant string values,
f.e.:
? "Harbour " - " Compiler"
* harbour/source/vm/hvm.c
% added optimization for string resizing in cVal1 - cVal2
* harbour/source/rtl/dateshb.c
% minor optimization - removed one not necessary ISCHAR()
2007-06-04 19:11 UTC+0300 Mindaugas Kavaliauskas (dbtopas/at/dbtopas.lt)
* harbour/include/hbexprop.h
* harbour/include/hbexprb.c

View File

@@ -1557,30 +1557,34 @@ static HB_EXPR_FUNC( hb_compExprUseFunCall )
#endif
{
/* TODO: EMPTY() (not done by Clipper) */
if( ( strcmp( "AT", pName->value.asSymbol ) == 0 ) && usCount == 2 )
if( strcmp( "AT", pName->value.asSymbol ) == 0 && usCount == 2 )
{
hb_compExprReduceAT( pSelf, HB_COMP_PARAM );
}
else if( ( strcmp( "CHR", pName->value.asSymbol ) == 0 ) && usCount )
else if( strcmp( "CHR", pName->value.asSymbol == 0 ) && usCount )
{
hb_compExprReduceCHR( pSelf, HB_COMP_PARAM );
}
else if( ( strcmp( "LEN", pName->value.asSymbol ) == 0 ) && usCount )
else if( strcmp( "LEN", pName->value.asSymbol == 0 ) && usCount )
{
if( HB_SUPPORT_HARBOUR )
hb_compExprReduceLEN( pSelf, HB_COMP_PARAM );
}
else if( ( strcmp( "ASC", pName->value.asSymbol ) == 0 ) && usCount )
else if( strcmp( "ASC", pName->value.asSymbol ) == 0 && usCount )
{
if( HB_SUPPORT_HARBOUR )
hb_compExprReduceASC( pSelf, HB_COMP_PARAM );
}
else if( ( ( strcmp( "STOD", pName->value.asSymbol ) == 0 ) ||
( strcmp( "HB_STOD", pName->value.asSymbol ) == 0 ) ) && usCount < 2 )
else if( ( strcmp( "STOD", pName->value.asSymbol ) == 0 ||
strcmp( "HB_STOD", pName->value.asSymbol ) == 0 ) && usCount < 2 )
{
if( HB_SUPPORT_HARBOUR )
hb_compExprReduceSTOD( pSelf, usCount, HB_COMP_PARAM );
}
else if( strcmp( "CTOD", pName->value.asSymbol ) == 0 && usCount )
{
hb_compExprReduceCTOD( pSelf, HB_COMP_PARAM );
}
}
}
break;

View File

@@ -195,6 +195,7 @@ extern BOOL hb_compExprReduceCHR( HB_EXPR_PTR, HB_COMP_DECL );
extern BOOL hb_compExprReduceLEN( HB_EXPR_PTR, HB_COMP_DECL );
extern BOOL hb_compExprReduceASC( HB_EXPR_PTR, HB_COMP_DECL );
extern BOOL hb_compExprReduceSTOD( HB_EXPR_PTR pSelf, USHORT usCount, HB_COMP_DECL );
extern BOOL hb_compExprReduceCTOD( HB_EXPR_PTR, HB_COMP_DECL );
HB_EXTERN_END

View File

@@ -85,6 +85,40 @@ static HB_EXPR_PTR hb_compExprReducePlusStrings( HB_EXPR_PTR pLeft, HB_EXPR_PTR
return pLeft;
}
static HB_EXPR_PTR hb_compExprReduceMinusStrings( HB_EXPR_PTR pLeft, HB_EXPR_PTR pRight, HB_COMP_DECL )
{
char * szText = pLeft->value.asString.string;
ULONG ulLen = pLeft->ulLength;
while( ulLen && szText[ ulLen - 1 ] == ' ' )
--ulLen;
if( pLeft->value.asString.dealloc )
{
pLeft->value.asString.string = (char *) hb_xrealloc( pLeft->value.asString.string, pLeft->ulLength + pRight->ulLength + 1 );
memcpy( pLeft->value.asString.string + ulLen,
pRight->value.asString.string, pRight->ulLength );
memset( pLeft->value.asString.string + ulLen + pRight->ulLength, ' ',
pLeft->ulLength - ulLen );
pLeft->ulLength += pRight->ulLength;
pLeft->value.asString.string[ pLeft->ulLength ] = '\0';
}
else
{
char *szString;
szString = (char *) hb_xgrab( pLeft->ulLength + pRight->ulLength + 1 );
memcpy( szString, pLeft->value.asString.string, ulLen );
memcpy( szString + ulLen, pRight->value.asString.string, pRight->ulLength );
memset( szString + ulLen + pRight->ulLength, ' ', pLeft->ulLength - ulLen );
pLeft->ulLength += pRight->ulLength;
szString[ pLeft->ulLength ] = '\0';
pLeft->value.asString.string = szString;
pLeft->value.asString.dealloc = TRUE;
}
HB_COMP_EXPR_FREE( pRight );
return pLeft;
}
HB_EXPR_PTR hb_compExprReduceMod( HB_EXPR_PTR pSelf, HB_COMP_DECL )
{
HB_EXPR_PTR pLeft, pRight;
@@ -378,8 +412,53 @@ HB_EXPR_PTR hb_compExprReduceMinus( HB_EXPR_PTR pSelf, HB_COMP_DECL )
}
else if( pLeft->ExprType == HB_ET_STRING && pRight->ExprType == HB_ET_STRING )
{
/* TODO:
*/
if( pRight->ulLength == 0 )
{
pSelf->ExprType = HB_ET_NONE; /* suppress deletion of operator components */
HB_COMP_EXPR_FREE( pSelf );
pSelf = pLeft;
HB_COMP_EXPR_FREE( pRight );
}
else if( pLeft->ulLength == 0 )
{
pSelf->ExprType = HB_ET_NONE; /* suppress deletion of operator components */
HB_COMP_EXPR_FREE( pSelf );
pSelf = pRight;
HB_COMP_EXPR_FREE( pLeft );
}
else
{
/* Do not reduce strings with the macro operator '&'
*/
char * szText = pLeft->value.asString.string;
ULONG ulLen = pLeft->ulLength;
BOOL fReduce = TRUE;
while( ulLen && szText[ ulLen - 1 ] == ' ' )
--ulLen;
while( ulLen-- )
{
if( *szText++ == '&' )
{
char ch = ulLen ? *szText : *pRight->value.asString.string;
if( ( ch >= 'A' && ch <= 'Z' ) ||
( ch >= 'a' && ch <= 'z' ) || ch == '_' ||
! HB_SUPPORT_HARBOUR )
{
fReduce = FALSE;
break;
}
}
}
if( fReduce )
{
pSelf->ExprType = HB_ET_NONE; /* suppress deletion of operator components */
HB_COMP_EXPR_FREE( pSelf );
pSelf = hb_compExprReduceMinusStrings( pLeft, pRight, HB_COMP_PARAM );
}
}
}
else
{
@@ -548,7 +627,10 @@ HB_EXPR_PTR hb_compExprReducePlus( HB_EXPR_PTR pSelf, HB_COMP_DECL )
if( ( ch >= 'A' && ch <= 'Z' ) ||
( ch >= 'a' && ch <= 'z' ) || ch == '_' ||
! HB_SUPPORT_HARBOUR )
{
fReduce = FALSE;
break;
}
}
}
@@ -1437,3 +1519,21 @@ BOOL hb_compExprReduceSTOD( HB_EXPR_PTR pSelf, USHORT usCount, HB_COMP_DECL )
return FALSE;
}
BOOL hb_compExprReduceCTOD( HB_EXPR_PTR pSelf, HB_COMP_DECL )
{
HB_EXPR_PTR pParms = pSelf->value.asFunCall.pParms;
HB_EXPR_PTR pArg = pParms->value.asList.pExprList;
if( pArg->ExprType == HB_ET_STRING && pArg->ulLength == 0 )
{
HB_EXPR_PTR pExpr = hb_compExprNewDate( 0, HB_COMP_PARAM );
HB_COMP_EXPR_FREE( pParms );
HB_COMP_EXPR_FREE( pSelf->value.asFunCall.pFunName );
memcpy( pSelf, pExpr, sizeof( HB_EXPR ) );
HB_COMP_EXPR_CLEAR( pExpr );
return TRUE;
}
return FALSE;
}

View File

@@ -207,7 +207,7 @@ HB_FUNC( HB_STOD )
#ifdef HB_FAST_STOD
hb_retds( hb_parc( 1 ) );
#else
hb_retds( ( ISCHAR( 1 ) && hb_parclen( 1 ) == 8 ) ? hb_parc( 1 ) : " " );
hb_retds( hb_parclen( 1 ) == 8 ? hb_parc( 1 ) : " " );
#endif
}

View File

@@ -2553,18 +2553,31 @@ static void hb_vmMinus( HB_ITEM_PTR pResult, HB_ITEM_PTR pItem1, HB_ITEM_PTR pIt
ULONG ulLen1 = pItem1->item.asString.length;
ULONG ulLen2 = pItem2->item.asString.length;
if( ulLen1 < ULONG_MAX - ulLen2 )
if( ulLen1 == 0 )
{
char * szNewString = ( char * ) hb_xgrab( ulLen1 + ulLen2 + 1 );
ULONG ulNewLen = ulLen1 + ulLen2;
hb_itemCopy( pResult, pItem2 );
pResult->type &= ~HB_IT_MEMOFLAG;
}
else if( ulLen2 == 0 )
{
if( pResult != pItem1 )
hb_itemCopy( pResult, pItem1 );
pResult->type &= ~HB_IT_MEMOFLAG;
}
else if( ulLen1 < ULONG_MAX - ulLen2 )
{
if( pResult != pItem1 )
{
hb_itemMove( pResult, pItem1 );
pItem1 = pResult;
}
hb_itemReSizeString( pItem1, ulLen1 + ulLen2 );
while( ulLen1 && pItem1->item.asString.value[ ulLen1 - 1 ] == ' ' )
ulLen1--;
hb_xmemcpy( szNewString, pItem1->item.asString.value, ulLen1 );
hb_xmemcpy( szNewString + ulLen1, pItem2->item.asString.value, ulLen2 );
hb_xmemset( szNewString + ulLen1 + ulLen2, ' ', pItem1->item.asString.length - ulLen1 );
hb_itemPutCPtr( pResult, szNewString, ulNewLen );
hb_xmemcpy( pItem1->item.asString.value + ulLen1,
pItem2->item.asString.value, ulLen2 );
hb_xmemset( pItem1->item.asString.value + ulLen1 + ulLen2, ' ',
pItem1->item.asString.length - ulLen1 - ulLen2 );
}
else
hb_errRT_BASE( EG_STROVERFLOW, 1210, NULL, "-", 2, pItem1, pItem2 );