summaryrefslogtreecommitdiff
path: root/cel
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2015-05-13 15:17:48 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2015-05-13 15:17:48 -0500
commit4505f5e6764d73b3e518bb74266b945f65597cc4 (patch)
treef95cf77112100d5846f67d9ee6b367e116b6d2dc /cel
parent4e482bf90161502fb7774b4ef6d129267555b27f (diff)
parente6daafb8a60b6018f0ded063fa26ba2b3e336b0b (diff)
Merge "cdr_pgsql, cel_pgsql: Store maximum buffer size to prevent reallocation"
Diffstat (limited to 'cel')
-rw-r--r--cel/cel_pgsql.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/cel/cel_pgsql.c b/cel/cel_pgsql.c
index 2bcee6ee1..20c0e4401 100644
--- a/cel/cel_pgsql.c
+++ b/cel/cel_pgsql.c
@@ -74,6 +74,7 @@ static char *table;
static char *schema;
static int connected = 0;
+/* Optimization to reduce number of memory allocations */
static int maxsize = 512, maxsize2 = 512;
static int usegmtime = 0;
@@ -375,6 +376,14 @@ static void pgsql_log(struct ast_event *event)
}
PQclear(result);
+ /* Next time, just allocate buffers that are that big to start with. */
+ if (ast_str_strlen(sql) > maxsize) {
+ maxsize = ast_str_strlen(sql);
+ }
+ if (ast_str_strlen(sql2) > maxsize2) {
+ maxsize2 = ast_str_strlen(sql2);
+ }
+
ast_log_cleanup:
ast_free(sql);
ast_free(sql2);