1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

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)'
This commit is contained in:
Anthony Clark 2019-11-12 19:31:09 -05:00 committed by Nate Berkopec
parent fcb99b91cc
commit befe00a864

View file

@ -10,6 +10,7 @@
#include "ext_help.h"
#include <assert.h>
#include <string.h>
#include <ctype.h>
#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,