[Asterisk-cvs] asterisk db.c,1.6,1.7

citats at lists.digium.com citats at lists.digium.com
Fri May 28 14:41:22 CDT 2004


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/home/citats/cvs/asterisk

Modified Files:
	db.c 
Log Message:
Use ast_strlen_zero in db.c and some optimizations.  Lets store the return value of strlen and use that rather than using strlen every time, and snprintf returns the length of the string

Index: db.c
===================================================================
RCS file: /usr/cvsroot/asterisk/db.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- db.c	2 Dec 2003 15:12:56 -0000	1.6
+++ db.c	28 May 2004 18:56:23 -0000	1.7
@@ -32,6 +32,7 @@
 #include <asterisk/options.h>
 #include <asterisk/astdb.h>
 #include <asterisk/cli.h>
+#include <asterisk/utils.h>
 #include "db1-ast/include/db.h"
 #include "asterisk.h"
 #include "astconf.h"
@@ -54,13 +55,14 @@
 
 static inline int keymatch(const char *key, const char *prefix)
 {
-	if (!strlen(prefix))
+	int preflen = strlen(prefix);
+	if (!preflen)
 		return 1;
 	if (!strcasecmp(key, prefix))
 		return 1;
-	if ((strlen(key) > strlen(prefix)) &&
-		!strncasecmp(key, prefix, strlen(prefix))) {
-		if (key[strlen(prefix)] == '/')
+	if ((strlen(key) > preflen) &&
+		!strncasecmp(key, prefix, preflen)) {
+		if (key[preflen] == '/')
 			return 1;
 	}
 	return 0;
@@ -110,7 +112,7 @@
 {
 	char fullkey[256];
 	DBT key, data;
-	int res;
+	int res, fullkeylen;
 
 	ast_mutex_lock(&dblock);
 	if (dbinit()) {
@@ -118,11 +120,11 @@
 		return -1;
 	}
 
-	snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
+	fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
 	memset(&key, 0, sizeof(key));
 	memset(&data, 0, sizeof(data));
 	key.data = fullkey;
-	key.size = strlen(fullkey) + 1;
+	key.size = fullkeylen + 1;
 	data.data = value;
 	data.size = strlen(value) + 1;
 	res = astdb->put(astdb, &key, &data, 0);
@@ -137,7 +139,7 @@
 {
 	char fullkey[256]="";
 	DBT key, data;
-	int res;
+	int res, fullkeylen;
 
 	ast_mutex_lock(&dblock);
 	if (dbinit()) {
@@ -145,12 +147,12 @@
 		return -1;
 	}
 
-	snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
+	fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
 	memset(&key, 0, sizeof(key));
 	memset(&data, 0, sizeof(data));
 	memset(value, 0, valuelen);
 	key.data = fullkey;
-	key.size = strlen(fullkey) + 1;
+	key.size = fullkeylen + 1;
 	
 	res = astdb->get(astdb, &key, &data, 0);
 	
@@ -178,7 +180,7 @@
 {
 	char fullkey[256];
 	DBT key;
-	int res;
+	int res, fullkeylen;
 
 	ast_mutex_lock(&dblock);
 	if (dbinit()) {
@@ -186,10 +188,10 @@
 		return -1;
 	}
 	
-	snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
+	fullkeylen = snprintf(fullkey, sizeof(fullkey), "/%s/%s", family, keys);
 	memset(&key, 0, sizeof(key));
 	key.data = fullkey;
-	key.size = strlen(fullkey) + 1;
+	key.size = fullkeylen + 1;
 	
 	res = astdb->del(astdb, &key, 0);
 	astdb->sync(astdb, 0);
@@ -314,8 +316,8 @@
 	struct ast_db_entry *last = NULL;
 	struct ast_db_entry *cur, *ret=NULL;
 
-	if (family && strlen(family)) {
-		if (keytree && strlen(keytree))
+	if (family && !ast_strlen_zero(family)) {
+		if (keytree && !ast_strlen_zero(keytree))
 			/* Family and key tree */
 			snprintf(prefix, sizeof(prefix), "/%s/%s", family, prefix);
 		else




More information about the svn-commits mailing list