From cd761624942ce5bd06fcf939400ed41b8166d37d Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Sat, 6 Feb 2021 17:31:03 +0000 Subject: [PATCH] swap check in vhost_* fns it's faster (statistically speaking) to first compute if the option is set and then fnmatch than the inverse. This way we can avoid unnecessary fnmatch. --- server.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/server.c b/server.c index a25f0a7..ec44649 100644 --- a/server.c +++ b/server.c @@ -63,8 +63,8 @@ vhost_lang(struct vhost *v, const char *path) return NULL; for (loc = &v->locations[1]; loc->match != NULL; ++loc) { - if (!fnmatch(loc->match, path, 0)) { - if (loc->lang != NULL) + if (loc->lang != NULL) { + if (!fnmatch(loc->match, path, 0)) return loc->lang; } } @@ -82,8 +82,8 @@ vhost_default_mime(struct vhost *v, const char *path) return default_mime; for (loc = &v->locations[1]; loc->match != NULL; ++loc) { - if (!fnmatch(loc->match, path, 0)) { - if (loc->default_mime != NULL) + if (loc->default_mime != NULL) { + if (!fnmatch(loc->match, path, 0)) return loc->default_mime; } } @@ -103,8 +103,8 @@ vhost_index(struct vhost *v, const char *path) return index; for (loc = &v->locations[1]; loc->match != NULL; ++loc) { - if (!fnmatch(loc->match, path, 0)) { - if (loc->index != NULL) + if (loc->index != NULL) { + if (!fnmatch(loc->match, path, 0)) return loc->index; } } @@ -123,8 +123,8 @@ vhost_auto_index(struct vhost *v, const char *path) return 0; for (loc = &v->locations[1]; loc->match != NULL; ++loc) { - if (!fnmatch(loc->match, path, 0)) { - if (loc->auto_index != 0) + if (loc->auto_index != 0) { + if (!fnmatch(loc->match, path, 0)) return loc->auto_index == 1; } } @@ -141,8 +141,8 @@ vhost_block_return(struct vhost *v, const char *path, int *code, const char **fm return 0; for (loc = &v->locations[1]; loc->match != NULL; ++loc) { - if (!fnmatch(loc->match, path, 0)) { - if (loc->block_code != 0) { + if (loc->block_code != 0) { + if (!fnmatch(loc->match, path, 0)) { *code = loc->block_code; *fmt = loc->block_fmt; return 1; @@ -164,8 +164,8 @@ vhost_strip(struct vhost *v, const char *path) return 0; for (loc = &v->locations[1]; loc->match != NULL; ++loc) { - if (!fnmatch(loc->match, path, 0)) { - if (loc->strip != 0) + if (loc->strip != 0) { + if (!fnmatch(loc->match, path, 0)) return loc->strip; } }