aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2008-07-23 11:52:18 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2008-07-23 11:52:18 +0000
commit1fd4a59f8b2223f7f727b06803552069ef7b508f (patch)
tree72c8789224b248f3ca47752f0a41817e73f0f383 /main
parente29afcb66573c0d7e28b705bfba2ce25d0a8b405 (diff)
minor optimization for stringfields: when a field is being set to a larger value than it currently contains and it happens to be the most recent field allocated from the currentl pool, it is possible to 'grow' it without having to waste the space it is currently using (or potentially even allocate a new pool)
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@132872 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/utils.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/main/utils.c b/main/utils.c
index 74ecfaf57..8906eff11 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -1223,6 +1223,7 @@ static int add_string_pool(struct ast_string_field_mgr *mgr, size_t size)
mgr->size = size;
mgr->space = size;
mgr->used = 0;
+ mgr->last_alloc = NULL;
return 0;
}
@@ -1259,12 +1260,36 @@ ast_string_field __ast_string_field_alloc_space(struct ast_string_field_mgr *mgr
result = mgr->pool->base + mgr->used;
mgr->used += needed;
mgr->space -= needed;
+ mgr->last_alloc = result;
return result;
}
+int __ast_string_field_index_grow(struct ast_string_field_mgr *mgr, size_t needed,
+ ast_string_field *fields, int index)
+{
+ int grow = needed - (strlen(fields[index]) + 1);
+
+ if (grow <= 0) {
+ return 0;
+ }
+
+ if (fields[index] != mgr->last_alloc) {
+ return 1;
+ }
+
+ if (mgr->space < grow) {
+ return 1;
+ }
+
+ mgr->space -= grow;
+ mgr->used += grow;
+
+ return 0;
+}
+
void __ast_string_field_index_build_va(struct ast_string_field_mgr *mgr,
- ast_string_field *fields, int num_fields,
- int index, const char *format, va_list ap1, va_list ap2)
+ ast_string_field *fields, int num_fields,
+ int index, const char *format, va_list ap1, va_list ap2)
{
size_t needed;
@@ -1285,6 +1310,7 @@ void __ast_string_field_index_build_va(struct ast_string_field_mgr *mgr,
}
fields[index] = mgr->pool->base + mgr->used;
+ mgr->last_alloc = fields[index];
mgr->used += needed;
mgr->space -= needed;
}