summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2018-01-18 10:44:24 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2018-01-18 10:44:24 +0100
commit44110f28e2502ad2fb5676b80ca420db470870ff (patch)
treecc034ec3de75ffca313ce0021877629d71544f0c
parent50bfbde712d00234306a52a86063eab65828d918 (diff)
afb-hreq: Dichotomic mimetype search
Change-Id: I6d906c31cdcf07c5404f1eb81cd44683976465f7 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afb-hreq.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/afb-hreq.c b/src/afb-hreq.c
index 70d54582..3a47766f 100644
--- a/src/afb-hreq.c
+++ b/src/afb-hreq.c
@@ -271,12 +271,12 @@ static const char *mimetype_fd_name(int fd, const char *filename)
const char *extension = strrchr(filename, '.');
if (extension) {
static const char *const known[][2] = {
+ /* keep it sorted for dichotomic search */
{ ".css", "text/css" },
{ ".gif", "image/gif" },
{ ".html", "text/html" },
{ ".htm", "text/html" },
{ ".ico", "image/x-icon"},
- /* TODO: CHECK ME { ".ico", "image/vnd.microsoft.icon" }, */
{ ".jpeg", "image/jpeg" },
{ ".jpg", "image/jpeg" },
{ ".js", "text/javascript" },
@@ -289,16 +289,20 @@ static const char *mimetype_fd_name(int fd, const char *filename)
{ ".wav", "audio/x-wav" },
{ ".xht", "application/xhtml+xml" },
{ ".xhtml", "application/xhtml+xml" },
- { ".xml", "application/xml" },
- { NULL, NULL }
+ { ".xml", "application/xml" }
};
- int i = 0;
- while (known[i][0]) {
- if (!strcasecmp(extension, known[i][0])) {
+ int i, c, l = 0, u = sizeof known / sizeof *known;
+ while (l < u) {
+ i = (l + u) >> 1;
+ c = strcasecmp(extension, known[i][0]);
+ if (!c) {
result = known[i][1];
break;
}
- i++;
+ if (c < 0)
+ u = i;
+ else
+ l = i + 1;
}
}
#endif