added the hint parameter to the sizer function

This commit is contained in:
hyung-hwan 2008-09-23 05:21:08 +00:00
parent 8488b72f98
commit b6e14c7be3
3 changed files with 9 additions and 7 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: str.h 366 2008-09-04 11:15:53Z baconevi $
* $Id: str.h 369 2008-09-22 11:21:08Z baconevi $
*
* {License}
*/
@ -237,7 +237,8 @@ ase_sizer_t ase_str_getsizer (
* DESCRIPTION:
* The ase_str_setsizer() function specify a new sizer for a dynamic string.
* With no sizer specified, the dynamic string doubles the current buffer
* when it needs to increase its size.
* when it needs to increase its size. The sizer function is passed a dynamic
* string and the minimum capacity required to hold data after resizing.
*/
void ase_str_setsizer (
ase_str_t* str /* a dynamic string */,

View File

@ -1,5 +1,5 @@
/*
* $Id: types.h 363 2008-09-04 10:58:08Z baconevi $
* $Id: types.h 369 2008-09-22 11:21:08Z baconevi $
*
* {License}
*/
@ -360,6 +360,6 @@ struct ase_ccls_t
* The ase_sizer_t is a generic type used by many other modules usually to
* get the new size for resizing data structure.
*/
typedef ase_size_t (*ase_sizer_t) (void* data);
typedef ase_size_t (*ase_sizer_t) (void* data, ase_size_t hint);
#endif

View File

@ -1,5 +1,5 @@
/*
* $Id: str_dyn.c 363 2008-09-04 10:58:08Z baconevi $
* $Id: str_dyn.c 369 2008-09-22 11:21:08Z baconevi $
*
* {License}
*/
@ -210,8 +210,9 @@ ase_size_t ase_str_ncat (ase_str_t* str, const ase_char_t* s, ase_size_t len)
}
else
{
/* let the user determine the new capacity */
ncapa = str->sizer (str);
/* let the user determine the new capacity.
* pass the minimum capacity required as a hint */
ncapa = str->sizer (str, str->size + len);
}
if (ase_str_setcapa (str, ncapa) == (ase_size_t)-1)