[master] 56d9cf802 Eliminate the detour over C-enum for 'resolve' argument
Poul-Henning Kamp
phk at FreeBSD.org
Wed Aug 7 08:23:11 UTC 2019
commit 56d9cf802616fcffa21b708d0120fcd4f1ba2970
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Aug 7 08:06:45 2019 +0000
Eliminate the detour over C-enum for 'resolve' argument
diff --git a/lib/libvmod_directors/Makefile.am b/lib/libvmod_directors/Makefile.am
index 706e24a30..73fccf7d5 100644
--- a/lib/libvmod_directors/Makefile.am
+++ b/lib/libvmod_directors/Makefile.am
@@ -13,9 +13,7 @@ libvmod_directors_la_SOURCES = \
shard_cfg.h \
shard_dir.c \
shard_dir.h \
- tbl_by.h \
- tbl_healthy.h \
- tbl_resolve.h
+ tbl_healthy.h
# Use vmodtool.py generated automake boilerplate
include $(srcdir)/automake_boilerplate.am
diff --git a/lib/libvmod_directors/shard_dir.h b/lib/libvmod_directors/shard_dir.h
index 56d2e6633..d67b6a7bf 100644
--- a/lib/libvmod_directors/shard_dir.h
+++ b/lib/libvmod_directors/shard_dir.h
@@ -34,11 +34,6 @@ enum healthy_e {
_HEALTHY_E_MAX
};
-enum resolve_e {
-#define VMODENUM(x) x,
-#include "tbl_resolve.h"
-};
-
struct vbitmap;
struct shard_circlepoint {
diff --git a/lib/libvmod_directors/tbl_by.h b/lib/libvmod_directors/tbl_by.h
deleted file mode 100644
index 97cb8287b..000000000
--- a/lib/libvmod_directors/tbl_by.h
+++ /dev/null
@@ -1,5 +0,0 @@
-VMODENUM(HASH)
-VMODENUM(URL)
-VMODENUM(KEY)
-VMODENUM(BLOB)
-#undef VMODENUM
diff --git a/lib/libvmod_directors/tbl_resolve.h b/lib/libvmod_directors/tbl_resolve.h
deleted file mode 100644
index c7c6d825d..000000000
--- a/lib/libvmod_directors/tbl_resolve.h
+++ /dev/null
@@ -1,3 +0,0 @@
-VMODENUM(NOW)
-VMODENUM(LAZY)
-#undef VMODENUM
diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c
index a940ff346..906214551 100644
--- a/lib/libvmod_directors/vmod_shard.c
+++ b/lib/libvmod_directors/vmod_shard.c
@@ -190,14 +190,6 @@ parse_healthy_e(VCL_ENUM e)
WRONG("illegal healthy enum");
}
-static enum resolve_e
-parse_resolve_e(VCL_ENUM e)
-{
-#define VMODENUM(n) if (e == VENUM(n)) return(n);
-#include "tbl_resolve.h"
- WRONG("illegal resolve enum");
-}
-
static const char * const healthy_str[_HEALTHY_E_MAX] = {
[_HEALTHY_E_INVALID] = "*INVALID*",
#define VMODENUM(n) [n] = #n,
@@ -608,7 +600,7 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard,
struct vmod_directors_shard_param pstk;
struct vmod_directors_shard_param *pp = NULL;
const struct vmod_directors_shard_param *ppt;
- enum resolve_e resolve;
+ VCL_ENUM resolve;
uint32_t args = shard_backendarg_mask_(a);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
@@ -616,14 +608,13 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard,
assert((args & ~arg_mask_) == 0);
if (args & arg_resolve)
- resolve = parse_resolve_e(a->resolve);
+ resolve = a->resolve;
else if (ctx->method & VCL_MET_TASK_H)
- resolve = LAZY;
+ resolve = VENUM(LAZY);
else
- resolve = NOW;
+ resolve = VENUM(NOW);
- switch (resolve) {
- case LAZY:
+ if (resolve == VENUM(LAZY)) {
if ((args & ~arg_resolve) == 0) {
AN(vshard->dir);
return (vshard->dir);
@@ -643,8 +634,7 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard,
if (pp == NULL)
return (NULL);
pp->vcl_name = vshard->shardd->name;
- break;
- case NOW:
+ } else if (resolve == VENUM(NOW)) {
if (ctx->method & VCL_MET_TASK_H) {
VRT_fail(ctx,
"shard .backend resolve=NOW can not be "
@@ -653,8 +643,7 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard,
}
pp = shard_param_stack(&pstk, vshard->shardd->param,
vshard->shardd->name);
- break;
- default:
+ } else {
WRONG("resolve enum");
}
@@ -675,10 +664,10 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard,
if (pp == NULL)
return (NULL);
- if (resolve == LAZY)
+ if (resolve == VENUM(LAZY))
return (vshard->dir);
- assert(resolve == NOW);
+ assert(resolve == VENUM(NOW));
shard_param_merge(pp, pp->defaults);
return (sharddir_pick_be(ctx, vshard->shardd,
shard_get_key(ctx, pp), pp->alt, pp->warmup,
More information about the varnish-commit
mailing list