diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e350ca96bc..2b827e0a19 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,23 @@ 2002-12-01 13:30 UTC+0100 Foo Bar */ +2007-06-04 22:40 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/hbzlib/include/stdafx.h + * harbour/contrib/hbzlib/include/ziparchive.h + * cleaned some warnings + + * harbour/include/hbexprb.c + * harbour/include/hbexprop.h + * harbour/source/common/expropt2.c + * restored Mindaugas code for UPPER optimization and added logic to + optimize UPPER for strings with only Latin letters, digit and spaces + just like in Clipper. Now code like: + ? Upper( chr(65)+chr(66)+chr(67)+"0123 QWE asd " ) + "ZXC" + is fully optimized at compile time to single string expression. + % optimized hb_compExprReduceCHR() by eliminating memory allocation + for new string + ! fixed typo in my previous commit + 2007-06-04 20:10 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbexprb.c * harbour/include/hbexprop.h diff --git a/harbour/contrib/hbzlib/include/stdafx.h b/harbour/contrib/hbzlib/include/stdafx.h index 1960a7c928..3205563710 100644 --- a/harbour/contrib/hbzlib/include/stdafx.h +++ b/harbour/contrib/hbzlib/include/stdafx.h @@ -109,7 +109,7 @@ #ifndef TRACE - #define TRACE + #define TRACE(a,b,c) #endif #if _MSC_VER >= 1300 diff --git a/harbour/contrib/hbzlib/include/ziparchive.h b/harbour/contrib/hbzlib/include/ziparchive.h index 23402203e0..4d6ce9f9fb 100644 --- a/harbour/contrib/hbzlib/include/ziparchive.h +++ b/harbour/contrib/hbzlib/include/ziparchive.h @@ -1290,7 +1290,7 @@ public: { if (m_iFileOpened != nothing) { - TRACE(_T("CZipArchive::SetDetectZlibMemoryLeaks: Set it before opening a file in the archive")); + TRACE(_T("CZipArchive::SetDetectZlibMemoryLeaks: Set it before opening a file in the archive"),__FILE__,__LINE__); return; } m_bDetectZlibMemoryLeaks = bDetect; @@ -1314,7 +1314,7 @@ public: { if (!IsClosed()) { - TRACE(_T("CZipArchive::SetConvertAfterOpen: Set it before opening the archive")); + TRACE(_T("CZipArchive::SetConvertAfterOpen: Set it before opening the archive"),__FILE__,__LINE__); return; } m_centralDir.m_bConvertAfterOpen = bConvertAfterOpen; @@ -1356,7 +1356,7 @@ public: { if (IsClosed()) { - TRACE(_T("CZipArchive::GetFindFastIndex: ZipArchive not yet opened.\n")); + TRACE(_T("CZipArchive::GetFindFastIndex: ZipArchive not yet opened.\n"),__FILE__,__LINE__); return -1; } diff --git a/harbour/include/hbexprb.c b/harbour/include/hbexprb.c index 993b46bb01..abeaeca8b3 100644 --- a/harbour/include/hbexprb.c +++ b/harbour/include/hbexprb.c @@ -1561,11 +1561,11 @@ static HB_EXPR_FUNC( hb_compExprUseFunCall ) { 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 ); @@ -1585,6 +1585,10 @@ static HB_EXPR_FUNC( hb_compExprUseFunCall ) { hb_compExprReduceCTOD( pSelf, HB_COMP_PARAM ); } + else if( strcmp( "UPPER", pName->value.asSymbol ) == 0 && usCount ) + { + hb_compExprReduceUPPER( pSelf, HB_COMP_PARAM ); + } } } break; diff --git a/harbour/include/hbexprop.h b/harbour/include/hbexprop.h index 08ab902aae..8e6f2014f2 100644 --- a/harbour/include/hbexprop.h +++ b/harbour/include/hbexprop.h @@ -196,6 +196,7 @@ 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 ); +extern BOOL hb_compExprReduceUPPER( HB_EXPR_PTR, HB_COMP_DECL ); HB_EXTERN_END diff --git a/harbour/source/common/expropt2.c b/harbour/source/common/expropt2.c index 395046c434..5ba0ef627f 100644 --- a/harbour/source/common/expropt2.c +++ b/harbour/source/common/expropt2.c @@ -1422,19 +1422,15 @@ BOOL hb_compExprReduceCHR( HB_EXPR_PTR pSelf, HB_COMP_DECL ) } else { - pExpr->value.asString.string = ( char * ) hb_xgrab( 2 ); - pExpr->value.asString.string[ 0 ] = ( char ) pArg->value.asNum.val.l; - pExpr->value.asString.string[ 1 ] = '\0'; - pExpr->value.asString.dealloc = TRUE; + pExpr->value.asString.string = ( char * ) hb_szAscii[ ( int ) pArg->value.asNum.val.l & 0xff ]; + pExpr->value.asString.dealloc = FALSE; pExpr->ulLength = 1; } } else { - pExpr->value.asString.string = ( char * ) hb_xgrab( 2 ); - pExpr->value.asString.string[ 0 ] = ( char ) ( ( unsigned int ) pArg->value.asNum.val.d & 0xff ); - pExpr->value.asString.string[ 1 ] = '\0'; - pExpr->value.asString.dealloc = TRUE; + pExpr->value.asString.string = ( char * ) hb_szAscii[ ( unsigned int ) pArg->value.asNum.val.d & 0xff ]; + pExpr->value.asString.dealloc = FALSE; pExpr->ulLength = 1; } @@ -1491,7 +1487,7 @@ BOOL hb_compExprReduceSTOD( HB_EXPR_PTR pSelf, USHORT usCount, 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 == 8 || pArg->ulLength == 0 ) ) { HB_EXPR_PTR pExpr = hb_compExprNewDate( pArg->ulLength == 0 ? 0 : @@ -1508,7 +1504,7 @@ BOOL hb_compExprReduceSTOD( HB_EXPR_PTR pSelf, USHORT usCount, HB_COMP_DECL ) else { HB_EXPR_PTR pExpr = hb_compExprNewDate( 0, HB_COMP_PARAM ); - + HB_COMP_EXPR_FREE( pSelf->value.asFunCall.pParms ); HB_COMP_EXPR_FREE( pSelf->value.asFunCall.pFunName ); memcpy( pSelf, pExpr, sizeof( HB_EXPR ) ); @@ -1523,7 +1519,7 @@ 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 ); @@ -1537,3 +1533,86 @@ BOOL hb_compExprReduceCTOD( HB_EXPR_PTR pSelf, HB_COMP_DECL ) return FALSE; } + +BOOL hb_compExprReduceUPPER( 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 ) + { + ULONG ulLen = pArg->ulLength; + BOOL fLower = FALSE; + + if( ulLen ) + { + char * szValue = pArg->value.asString.string; + do + { + char c = * szValue++; + if( c >= 'a' && c <= 'z' ) + fLower = TRUE; + else if( !( ( c >= 'A' && c <= 'Z' ) || + ( c >= '0' && c <= '9' ) || c == ' ' ) ) + break; + } + while( --ulLen ); + } + + if( ulLen == 0 ) + { + HB_EXPR_PTR pExpr; + char * szValue; + BOOL fDealloc; + + if( fLower ) + { + if( pArg->ulLength == 1 ) + { + szValue = ( char * ) hb_szAscii[ toupper( (unsigned char) + pArg->value.asString.string[ 0 ] ) ]; + fDealloc = FALSE; + } + else + { + if( pArg->value.asString.dealloc ) + { + szValue = pArg->value.asString.string; + pArg->value.asString.dealloc = FALSE; + fDealloc = TRUE; + } + else + { + szValue = ( char * ) hb_xgrab( pArg->ulLength + 1 ); + memcpy( szValue, pArg->value.asString.string, pArg->ulLength + 1 ); + fDealloc = TRUE; + } + do + szValue[ ulLen ] = toupper( (unsigned char) szValue[ ulLen ] ); + while( ++ulLen < pArg->ulLength ); + } + } + else + { + szValue = pArg->value.asString.string; + fDealloc = pArg->value.asString.dealloc; + pArg->value.asString.dealloc = FALSE; + } + + pExpr = HB_COMP_EXPR_NEW( HB_ET_STRING ); + pExpr->ValType = HB_EV_STRING; + pExpr->value.asString.string = szValue; + pExpr->value.asString.dealloc = fDealloc; + pExpr->ulLength = pArg->ulLength; + + 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; +}