[master] 7fe9889 Optimize the compiled code by generating static const gethdr_s's
Poul-Henning Kamp
phk at varnish-cache.org
Wed Oct 24 10:07:58 CEST 2012
commit 7fe9889a6b280b190f3cb4517f2ddc83317bc80c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Oct 24 08:07:27 2012 +0000
Optimize the compiled code by generating static const gethdr_s's
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index 6efff05..dbf31af 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -838,9 +838,9 @@ for i in sp_variables:
if len(i[2]) == 0:
fo.write('\t NULL,\t/* No reads allowed */\n')
elif typ == "HEADER":
- fo.write('\t "VRT_MkGethdr(req, HDR_')
+ fo.write('\t "HDR_')
fo.write(i[0].split(".")[0].upper())
- fo.write(', ",\n')
+ fo.write('",\n')
else:
fo.write('\t "VRT_r_%s(req)",\n' % cnam)
fh.write(ctyp + " VRT_r_%s(const %s);\n" % (cnam, i[4]))
@@ -849,9 +849,9 @@ for i in sp_variables:
if len(i[3]) == 0:
fo.write('\t NULL,\t/* No writes allowed */\n')
elif typ == "HEADER":
- fo.write('\t "VRT_SetHdr(req, VRT_MkGethdr(req, HDR_')
+ fo.write('\t "HDR_')
fo.write(i[0].split(".")[0].upper())
- fo.write(', ",\n')
+ fo.write('",\n')
else:
fo.write('\t "VRT_l_%s(req, ",\n' % cnam)
fh.write("void VRT_l_%s(%s, " % (cnam, i[4]))
@@ -861,7 +861,6 @@ for i in sp_variables:
fh.write(ctyp + ", ...);\n")
restrict(fo, i[3])
- fo.write('\t 0,\n') # XXX: shoule be NULL
fo.write("\t},\n")
fo.write("\t{ NULL }\n};\n")
diff --git a/lib/libvcl/vcc_compile.h b/lib/libvcl/vcc_compile.h
index c85af5b..a8c6e02 100644
--- a/lib/libvcl/vcc_compile.h
+++ b/lib/libvcl/vcc_compile.h
@@ -205,8 +205,6 @@ struct var {
unsigned r_methods;
const char *lname;
unsigned w_methods;
- const char *http;
- const char *hdr;
};
struct method {
diff --git a/lib/libvcl/vcc_var.c b/lib/libvcl/vcc_var.c
index 661ca85..5afec43 100644
--- a/lib/libvcl/vcc_var.c
+++ b/lib/libvcl/vcc_var.c
@@ -33,6 +33,7 @@
#include <string.h>
#include "vcc_compile.h"
+#include "vct.h"
/*--------------------------------------------------------------------*/
@@ -42,8 +43,10 @@ vcc_Var_Wildcard(struct vcc *tl, const struct token *t, const struct symbol *wc)
struct symbol *sym;
struct var *v;
const struct var *vh;
- int l;
+ int l, i;
+ char c;
char buf[258];
+ char cnam[256];
vh = wc->var;
@@ -55,14 +58,27 @@ vcc_Var_Wildcard(struct vcc *tl, const struct token *t, const struct symbol *wc)
v->r_methods = vh->r_methods;
v->w_methods = vh->w_methods;
v->fmt = vh->fmt;
- v->http = vh->http;
+
+ /* Create a C-name version of the header name */
l = strlen(v->name + vh->len) + 1;
+ for (i = 0; i < l - 1; i++) {
+ c = *(v->name + vh->len + i);
+ if (vct_isalpha(c) || vct_isdigit(c))
+ cnam[i] = c;
+ else
+ cnam[i] = '_';
+ }
+ cnam[i] = '\0';
+
+ /* Create the static identifier */
+ Fh(tl, 0, "static const struct gethdr_s VGC_%s_%s =\n",
+ vh->rname, cnam);
+ Fh(tl, 0, " { %s, \"\\%03o%s:\"};\n",
+ vh->rname, (unsigned)l, v->name + vh->len);
- bprintf(buf, "\\%03o%s:", (unsigned)l, v->name + vh->len);
- v->hdr = TlDup(tl, buf);
- bprintf(buf, "%s\"%s\")", vh->rname, v->hdr);
+ bprintf(buf, "&VGC_%s_%s", vh->rname, cnam);
v->rname = TlDup(tl, buf);
- bprintf(buf, "%s\"%s\"), ", vh->lname, v->hdr);
+ bprintf(buf, "VRT_SetHdr(req, %s, ", v->rname);
v->lname = TlDup(tl, buf);
sym = VCC_AddSymbolTok(tl, t, SYM_VAR);
More information about the varnish-commit
mailing list