Skip to content

Commit

Permalink
http11: Remove qsort code paths [changelog skip] (#2073)
Browse files Browse the repository at this point in the history
* 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)'
  • Loading branch information
AnthonyClark authored and nateberkopec committed Nov 13, 2019
1 parent fcb99b9 commit befe00a
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions ext/puma_http11/puma_http11.c
Expand Up @@ -10,6 +10,7 @@
#include "ext_help.h"
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include "http11_parser.h"

#ifndef MANAGED_STRINGS
Expand Down Expand Up @@ -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;
Expand All @@ -142,36 +128,17 @@ 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++) {
if (cf->len == flen && !memcmp(cf->name, field, flen))
return cf->value;
}
return Qnil;
#endif /* !HAVE_QSORT_BSEARCH */
}

void http_field(puma_parser* hp, const char *field, size_t flen,
Expand Down

0 comments on commit befe00a

Please sign in to comment.