From: José Bollo Date: Thu, 18 Jan 2018 09:44:24 +0000 (+0100) Subject: afb-hreq: Dichotomic mimetype search X-Git-Tag: flounder_5.99.1~97 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=44110f28e2502ad2fb5676b80ca420db470870ff;p=src%2Fapp-framework-binder.git afb-hreq: Dichotomic mimetype search Change-Id: I6d906c31cdcf07c5404f1eb81cd44683976465f7 Signed-off-by: José Bollo --- 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