[Asterisk-code-review] cdr/cdr pgsql.c, cel/cel pgsql.c: It justified the use of 2 ... (asterisk[master])
Rodrigo Ramirez Norambuena
asteriskteam at digium.com
Fri May 8 14:19:12 CDT 2015
Rodrigo Ramirez Norambuena has uploaded a new change for review.
https://gerrit.asterisk.org/415
Change subject: cdr/cdr_pgsql.c, cel/cel_pgsql.c: It justified the use of 2 vars of size buffer
......................................................................
cdr/cdr_pgsql.c, cel/cel_pgsql.c: It justified the use of 2 vars of size buffer
It is used two var to assignate buffer values of sqls. This dont have utility
because used the same value.
The original reason was utilized for resize the
size of buffer and reduced number of memory allocations. This change apply this
finality.
Change-Id: I55385899f1c06dee47e4274c2d21538037b2d895
---
M cdr/cdr_pgsql.c
M cel/cel_pgsql.c
2 files changed, 19 insertions(+), 0 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/15/415/1
diff --git a/cdr/cdr_pgsql.c b/cdr/cdr_pgsql.c
index 310411c..1941205 100644
--- a/cdr/cdr_pgsql.c
+++ b/cdr/cdr_pgsql.c
@@ -75,6 +75,7 @@
static char *tz;
static int connected = 0;
+/* Optimization to reduce number of memory allocations */
static int maxsize = 512, maxsize2 = 512;
static time_t connect_time = 0;
static int totalrecords = 0;
@@ -453,6 +454,15 @@
records++;
}
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_free(sql);
ast_free(sql2);
}
diff --git a/cel/cel_pgsql.c b/cel/cel_pgsql.c
index 2d7f0df..c5c4fa9 100644
--- a/cel/cel_pgsql.c
+++ b/cel/cel_pgsql.c
@@ -71,6 +71,7 @@
static char *table;
static int connected = 0;
+/* Optimization to reduce number of memory allocations */
static int maxsize = 512, maxsize2 = 512;
static int usegmtime = 0;
@@ -372,6 +373,14 @@
}
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);
--
To view, visit https://gerrit.asterisk.org/415
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I55385899f1c06dee47e4274c2d21538037b2d895
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Rodrigo Ramirez Norambuena <decipher.hk at gmail.com>
More information about the asterisk-code-review
mailing list