optimize the 'quick response' code a bit more... no more malloc() or memset() for each response

expand stringfields API a bit to allow reusing the stringfield pool on a structure when needed, and remove some unnecessary code when the structure was being freed


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@45408 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2006-10-17 22:24:10 +00:00
parent 5658b611e5
commit 227d415709
5 changed files with 58 additions and 38 deletions

View File

@@ -248,6 +248,7 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
} \
} while (0)
#endif
/*!
\brief Set a field to a simple string value
\param x Pointer to a structure containing fields
@@ -262,6 +263,7 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
#define ast_string_field_logset(x, field, data, logstr) \
ast_string_field_index_logset(x, ast_string_field_index(x, field), data, logstr)
#endif
/*!
\brief Set a field to a complex (built) value
\param x Pointer to a structure containing fields
@@ -312,7 +314,7 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
ast_string_field_index_free(x, ast_string_field_index(x, field))
/*!
\brief Free all fields (and the storage pool) in a structure
\brief Free the stringfield storage pools attached to a structure
\param x Pointer to a structure containing fields
\return nothing
@@ -320,15 +322,29 @@ void __ast_string_field_index_build(struct ast_string_field_mgr *mgr,
structure; it should only be called immediately before freeing
the structure itself.
*/
#define ast_string_field_free_all(x) do { \
int index; \
#define ast_string_field_free_pools(x) do { \
struct ast_string_field_pool *this, *prev; \
for (index = 0; index < ast_string_field_count(x); index ++) \
ast_string_field_index_free(x, index); \
for (this = (x)->__field_mgr.pool; this; this = prev) { \
prev = this->prev; \
free(this); \
} \
} while(0)
/*!
\brief Free the stringfields in a structure
\param x Pointer to a structure containing fields
\return nothing
After calling this macro, the most recently allocated pool
attached to the structure will be available for use by
stringfields again.
*/
#define ast_string_field_free_all(x) do { \
int index; \
for (index = 0; index < ast_string_field_count(x); index++) \
ast_string_field_index_free(x, index); \
(x)->__field_mgr.used = 0; \
(x)->__field_mgr.space = (x)->__field_mgr.size; \
} while(0)
#endif /* _ASTERISK_STRINGFIELDS_H */