From 7aaeaa714e9037c273dba4a8032a45003b098bcc Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Wed, 9 Dec 2009 20:26:18 +0000 Subject: [PATCH] 2009-12-09 21:25 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/contrib/xhb/fparse.c ! fixed few GPF traps and memory leaks % added some minor optimization I strongly suggest to use hb_aTokens() and hb_token*() functions. They have more options and for really large data many times (even hundreds times) faster. --- harbour/ChangeLog | 9 +++++++++ harbour/contrib/xhb/fparse.c | 33 +++++++++++++-------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 216fa6000f..8271bd170c 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,15 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-09 21:25 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/contrib/xhb/fparse.c + ! fixed few GPF traps and memory leaks + % added some minor optimization + + I strongly suggest to use hb_aTokens() and hb_token*() functions. + They have more options and for really large data many times + (even hundreds times) faster. + 2009-12-09 21:17 UTC+0100 Viktor Szakats (harbour.01 syenar.hu) * contrib/hbgd/gdwrp.c * Formatting (deleted unnecessary returns and blocks). diff --git a/harbour/contrib/xhb/fparse.c b/harbour/contrib/xhb/fparse.c index a7da42b219..76486bf32b 100644 --- a/harbour/contrib/xhb/fparse.c +++ b/harbour/contrib/xhb/fparse.c @@ -398,9 +398,7 @@ HB_FUNC( FPARSE ) nByte = pDelim ? (BYTE) hb_itemGetCPtr( pDelim )[0] : (BYTE) 44; /* the main array */ - pArray = hb_itemNew( NULL ); - hb_arrayNew( pArray, 0 ); - + pArray = hb_itemArrayNew( 0 ); pItem = hb_itemNew( NULL ); /* book memory for line to read */ @@ -433,7 +431,7 @@ HB_FUNC( FPARSE ) } /* return main array */ - hb_itemReturnForward( pArray ); + hb_itemReturnRelease( pArray ); hb_itemRelease( pItem ); /* clean up */ @@ -480,9 +478,7 @@ HB_FUNC( FPARSEEX ) nByte = pDelim ? (BYTE) hb_itemGetCPtr( pDelim )[0] : (BYTE) 44; /* the main array */ - pArray = hb_itemNew( NULL ); - hb_arrayNew( pArray, 0 ); - + pArray = hb_itemArrayNew( 0 ); pSubArray = hb_itemNew( NULL ); /* book memory for line to read */ @@ -502,7 +498,7 @@ HB_FUNC( FPARSEEX ) } /* return main array */ - hb_itemReturnForward( pArray ); + hb_itemReturnRelease( pArray ); hb_itemRelease( pSubArray ); /* clean up */ @@ -673,22 +669,19 @@ HB_FUNC( FCHARCOUNT ) /*----------------------------------------------------------------------------*/ HB_FUNC( FPARSELINE ) { - PHB_ITEM pReturn = NULL; + PHB_ITEM pArray = NULL; int iWords = 0; + const char * szText; - hb_arrayNew( pReturn, 0 ); + pArray = hb_itemArrayNew( 0 ); + szText = hb_parc( 1 ); - if ( HB_ISCHAR(1) ) + if( szText ) { - PHB_ITEM pDelim = hb_param( 2, HB_IT_STRING ); - - hb_ParseLine( pReturn, hb_parcx(1), pDelim ? hb_itemGetCPtr( pDelim )[ 0 ] : (int) ',', &iWords ); + const char * szDelim = hb_parc( 2 ); + hb_ParseLine( pArray, szText, szDelim ? ( unsigned char ) *szDelim : ',', &iWords ); } - hb_itemReturnForward( pReturn ); - - if ( hb_pcount() >= 3 ) - { - hb_stornl( iWords, 3 ); - } + hb_itemReturnRelease( pArray ); + hb_stornl( iWords, 3 ); }