From befe00a86447ffaedfad8b94eb5c4f2208f8bf7a Mon Sep 17 00:00:00 2001 From: Anthony Clark Date: Tue, 12 Nov 2019 19:31:09 -0500 Subject: [PATCH] http11: Remove qsort code paths [changelog skip] (#2073) * http11: Remove unused qsort/bsearch code paths [changelog skip] * Explicitly include ctype.h to fix compilation warning [changelog skip] Had the following warning during compilation without the include: warning: implicitly declaring library function 'isspace' with type 'int (int)' --- ext/puma_http11/puma_http11.c | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/ext/puma_http11/puma_http11.c b/ext/puma_http11/puma_http11.c index 7ac1b478b5..89ed1af832 100644 --- a/ext/puma_http11/puma_http11.c +++ b/ext/puma_http11/puma_http11.c @@ -10,6 +10,7 @@ #include "ext_help.h" #include #include +#include #include "http11_parser.h" #ifndef MANAGED_STRINGS @@ -111,21 +112,6 @@ static struct common_field common_http_fields[] = { # undef f }; -/* - * qsort(3) and bsearch(3) improve average performance slightly, but may - * not be worth it for lack of portability to certain platforms... - */ -#if defined(HAVE_QSORT_BSEARCH) -/* sort by length, then by name if there's a tie */ -static int common_field_cmp(const void *a, const void *b) -{ - struct common_field *cfa = (struct common_field *)a; - struct common_field *cfb = (struct common_field *)b; - signed long diff = cfa->len - cfb->len; - return diff ? diff : memcmp(cfa->name, cfb->name, cfa->len); -} -#endif /* HAVE_QSORT_BSEARCH */ - static void init_common_fields(void) { unsigned i; @@ -142,28 +128,10 @@ static void init_common_fields(void) } rb_global_variable(&cf->value); } - -#if defined(HAVE_QSORT_BSEARCH) - qsort(common_http_fields, - ARRAY_SIZE(common_http_fields), - sizeof(struct common_field), - common_field_cmp); -#endif /* HAVE_QSORT_BSEARCH */ } static VALUE find_common_field_value(const char *field, size_t flen) { -#if defined(HAVE_QSORT_BSEARCH) - struct common_field key; - struct common_field *found; - key.name = field; - key.len = (signed long)flen; - found = (struct common_field *)bsearch(&key, common_http_fields, - ARRAY_SIZE(common_http_fields), - sizeof(struct common_field), - common_field_cmp); - return found ? found->value : Qnil; -#else /* !HAVE_QSORT_BSEARCH */ unsigned i; struct common_field *cf = common_http_fields; for(i = 0; i < ARRAY_SIZE(common_http_fields); i++, cf++) { @@ -171,7 +139,6 @@ static VALUE find_common_field_value(const char *field, size_t flen) return cf->value; } return Qnil; -#endif /* !HAVE_QSORT_BSEARCH */ } void http_field(puma_parser* hp, const char *field, size_t flen,