[master] d36344d De-const the parspec structs and modify them directly to avoid various pointless malloc'ing.

Poul-Henning Kamp phk at varnish-cache.org
Tue Nov 12 14:48:47 CET 2013


commit d36344d35957ee964a6674f16df7142980e991c8
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Nov 12 13:48:20 2013 +0000

    De-const the parspec structs and modify them directly to avoid
    various pointless malloc'ing.

diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index 8c32bcd..b4ec68a 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -51,7 +51,7 @@
 
 struct params mgt_param;
 static int nparspec;
-static struct parspec const ** parspecs;
+static struct parspec ** parspecs;
 static const int margin1 = 8;
 static int margin2 = 0;
 static const int wrap_at = 72;
@@ -89,7 +89,7 @@ static const char PROTECTED_TEXT[] =
 
 /*--------------------------------------------------------------------*/
 
-static const struct parspec *
+static struct parspec *
 mcf_findpar(const char *name, int *idx)
 {
 	int i;
@@ -278,17 +278,14 @@ MCF_ParamProtect(struct cli *cli, const char *args)
 		return;
 	}
 	for (i = 1; av[i] != NULL; i++) {
-		if (mcf_findpar(av[i], &j) == NULL) {
+		pp = mcf_findpar(av[i], &j);
+		if (pp == NULL) {
 			VCLI_Out(cli, "Unknown parameter %s", av[i]);
 			VCLI_SetResult(cli, CLIS_PARAM);
 			VAV_Free(av);
 			return;
 		}
-		pp = calloc(sizeof *pp, 1L);
-		AN(pp);
-		memcpy(pp, parspecs[j], sizeof *pp);
 		pp->flags |= PROTECTED;
-		parspecs[j] = pp;
 	}
 	VAV_Free(av);
 }
@@ -353,9 +350,9 @@ mcf_parspec_cmp(const void *a, const void *b)
 }
 
 static void
-MCF_AddParams(const struct parspec *ps)
+MCF_AddParams(struct parspec *ps)
 {
-	const struct parspec *pp;
+	struct parspec *pp;
 	const char *s;
 	int n;
 
@@ -437,18 +434,11 @@ MCF_CollectParams(void)
 void
 MCF_SetDefault(const char *param, const char *def)
 {
-	struct parspec *pn;
-	int i;
+	struct parspec *pp;
 
-	for (i = 0; i < nparspec; i++)
-		if (!strcmp(parspecs[i]->name, param))
-			break;
-	assert(i < nparspec);
-	pn = malloc(sizeof *pn);
-	AN(pn);
-	*pn  = *(parspecs[i]);
-	pn->def = def;
-	parspecs[i] = pn;
+	pp = mcf_findpar(param, NULL);
+	AN(pp);
+	pp->def = def;
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/mgt/mgt_param.h b/bin/varnishd/mgt/mgt_param.h
index c30394f..6a9319b 100644
--- a/bin/varnishd/mgt/mgt_param.h
+++ b/bin/varnishd/mgt/mgt_param.h
@@ -69,10 +69,10 @@ int tweak_generic_uint(struct vsb *vsb,
     volatile unsigned *dest, const char *arg, unsigned min, unsigned max);
 
 /* mgt_param_tbl.c */
-extern const struct parspec mgt_parspec[];
+extern struct parspec mgt_parspec[];
 
 /* mgt_param_vsl.c */
-extern const struct parspec VSL_parspec[];
+extern struct parspec VSL_parspec[];
 
 /* mgt_pool.c */
-extern const struct parspec WRK_parspec[];
+extern struct parspec WRK_parspec[];
diff --git a/bin/varnishd/mgt/mgt_param_bits.c b/bin/varnishd/mgt/mgt_param_bits.c
index 57b26ce..86b6f80 100644
--- a/bin/varnishd/mgt/mgt_param_bits.c
+++ b/bin/varnishd/mgt/mgt_param_bits.c
@@ -234,7 +234,7 @@ tweak_feature(struct vsb *vsb, const struct parspec *par, const char *arg)
  * The parameter table itself
  */
 
-const struct parspec VSL_parspec[] = {
+struct parspec VSL_parspec[] = {
 	{ "vsl_mask", tweak_vsl_mask, NULL, 0, 0,
 		"Mask individual VSL messages from being logged.\n"
 		"\tdefault\tSet default value\n"
diff --git a/bin/varnishd/mgt/mgt_param_tbl.c b/bin/varnishd/mgt/mgt_param_tbl.c
index d6247d7..a8c1e4e 100644
--- a/bin/varnishd/mgt/mgt_param_tbl.c
+++ b/bin/varnishd/mgt/mgt_param_tbl.c
@@ -51,7 +51,7 @@
  * XXX: we should generate the relevant section of varnishd.1 from here.
  */
 
-const struct parspec mgt_parspec[] = {
+struct parspec mgt_parspec[] = {
 	{ "user", tweak_user, NULL, 0, 0,
 		"The unprivileged user to run as.",
 		MUST_RESTART,
diff --git a/bin/varnishd/mgt/mgt_pool.c b/bin/varnishd/mgt/mgt_pool.c
index 61b8425..8b3fe7e 100644
--- a/bin/varnishd/mgt/mgt_pool.c
+++ b/bin/varnishd/mgt/mgt_pool.c
@@ -98,7 +98,7 @@ tweak_thread_pool_max(struct vsb *vsb, const struct parspec *par,
 
 /*--------------------------------------------------------------------*/
 
-const struct parspec WRK_parspec[] = {
+struct parspec WRK_parspec[] = {
 	{ "thread_pools", tweak_uint, &mgt_param.wthread_pools,
 		1, UINT_MAX,
 		"Number of worker thread pools.\n"



More information about the varnish-commit mailing list