Browse Source

[core] array_init() arg for initial size

personal/stbuehler/ci-build
Glenn Strauss 2 years ago
parent
commit
24680a9142
  1. 10
      src/array.c
  2. 2
      src/array.h
  3. 2
      src/base.h
  4. 10
      src/configfile.c
  5. 4
      src/configparser.y
  6. 2
      src/data_config.c
  7. 2
      src/mod_auth.c
  8. 6
      src/mod_extforward.c
  9. 2
      src/mod_magnet.c
  10. 2
      src/mod_maxminddb.c
  11. 2
      src/mod_openssl.c
  12. 4
      src/mod_ssi.c
  13. 2
      src/mod_status.c
  14. 12
      src/server.c
  15. 8
      src/status_counter.h
  16. 6
      src/t/test_array.c
  17. 4
      src/t/test_mod_access.c
  18. 2
      src/t/test_mod_evhost.c

10
src/array.c

@ -12,8 +12,8 @@
#include <assert.h>
__attribute_cold__
static void array_extend(array * const a) {
a->size += 16;
static void array_extend(array * const a, uint32_t n) {
a->size += n;
a->data = realloc(a->data, sizeof(*a->data) * a->size);
a->sorted = realloc(a->sorted, sizeof(*a->sorted) * a->size);
force_assert(a->data);
@ -21,12 +21,12 @@ static void array_extend(array * const a) {
memset(a->data+a->used, 0, (a->size-a->used)*sizeof(*a->data));
}
array *array_init(void) {
array *array_init(uint32_t n) {
array *a;
a = calloc(1, sizeof(*a));
force_assert(a);
array_extend(a);
if (n) array_extend(a, n);
return a;
}
@ -216,7 +216,7 @@ static void array_insert_data_at_pos(array * const a, data_unset * const entry,
force_assert(a->used + 1 <= INT32_MAX);
if (a->size == a->used) {
array_extend(a);
array_extend(a, 16);
}
const uint32_t ndx = a->used++;

2
src/array.h

@ -56,7 +56,7 @@ typedef struct {
data_integer *data_integer_init(void);
__attribute_returns_nonnull__
array *array_init(void);
array *array_init(uint32_t n);
__attribute_cold__
void array_copy_array(array *dst, const array *src);

2
src/base.h

@ -368,7 +368,7 @@ struct server {
*
* fastcgi.backend.<key>.disconnects = ...
*/
array *status;
array status;
server_config srvconf;

10
src/configfile.c

@ -311,7 +311,7 @@ static void config_compat_module_load (server *srv) {
if (prepend_mod_indexfile) {
/* mod_indexfile has to be loaded before mod_fastcgi and friends */
array *modules = array_init();
array *modules = array_init(srv->srvconf.modules->used+4);
array_insert_value(modules, CONST_STR_LEN("mod_indexfile"));
for (uint32_t i = 0; i < srv->srvconf.modules->used; ++i) {
@ -1042,8 +1042,8 @@ void config_free(server *srv) {
}
void config_init(server *srv) {
srv->config_context = array_init();
srv->srvconf.config_touched = array_init();
srv->config_context = array_init(16);
srv->srvconf.config_touched = array_init(128);
srv->srvconf.port = 0;
srv->srvconf.dont_daemonize = 0;
@ -1065,9 +1065,9 @@ void config_init(server *srv) {
| HTTP_PARSEOPT_URL_NORMALIZE_PATH_2F_DECODE
| HTTP_PARSEOPT_URL_NORMALIZE_PATH_DOTSEG_REMOVE;
srv->srvconf.modules = array_init();
srv->srvconf.modules = array_init(16);
srv->srvconf.modules_dir = buffer_init_string(LIBRARY_DIR);
srv->srvconf.upload_tempdirs = array_init();
srv->srvconf.upload_tempdirs = array_init(2);
}

4
src/configparser.y

@ -345,7 +345,7 @@ value(A) ::= array(B). {
B = NULL;
}
array(A) ::= LPARAN RPARAN. {
A = array_init();
A = array_init(8);
}
array(A) ::= LPARAN aelements(B) RPARAN. {
A = B;
@ -382,7 +382,7 @@ aelements(A) ::= aelements(C) COMMA. {
aelements(A) ::= aelement(B). {
A = NULL;
if (ctx->ok) {
A = array_init();
A = array_init(4);
array_insert_unique(A, B);
B = NULL;
}

2
src/data_config.c

@ -137,7 +137,7 @@ data_config *data_config_init(void) {
ds->comp_tag = buffer_init();
ds->comp_key = buffer_init();
ds->value = array_init();
ds->value = array_init(4);
vector_config_weak_init(&ds->children);
ds->type = TYPE_CONFIG;

2
src/mod_auth.c

@ -430,7 +430,7 @@ SETDEFAULTS_FUNC(mod_auth_set_defaults) {
break;
case 1: /* auth.require */
if (array_is_kvarray(cpv->v.a)) {
array * const a = array_init();
array * const a = array_init(4);
if (HANDLER_GO_ON !=
mod_auth_require_parse_array(srv, cpv->v.a, a)) {
array_free(a);

6
src/mod_extforward.c

@ -419,7 +419,7 @@ SETDEFAULTS_FUNC(mod_extforward_set_defaults) {
* is not specified or is empty (and not using hap_PROXY) */
if (!p->defaults.hap_PROXY
&& (NULL == p->defaults.headers || 0 == p->defaults.headers->used)) {
p->defaults.headers = p->default_headers = array_init();
p->defaults.headers = p->default_headers = array_init(2);
array_insert_value(p->default_headers,CONST_STR_LEN("X-Forwarded-For"));
array_insert_value(p->default_headers,CONST_STR_LEN("Forwarded-For"));
}
@ -466,7 +466,7 @@ SETDEFAULTS_FUNC(mod_extforward_set_defaults) {
*/
static array *extract_forward_array(const buffer *pbuffer)
{
array *result = array_init();
array *result = array_init(8);
if (!buffer_string_is_empty(pbuffer)) {
const char *base, *curr;
/* state variable, 0 means not in string, 1 means in string */
@ -1610,7 +1610,7 @@ static int mod_extforward_hap_PROXY_v2 (connection * const con,
subtlv = (struct pp2_tlv *)((char *)subtlv + 3 + n);
n = ((uint32_t)subtlv->length_hi << 8) | subtlv->length_lo;
if (3 + n > subsz) break; /*(invalid TLV)*/
if (NULL == hctx->env) hctx->env = array_init();
if (NULL == hctx->env) hctx->env = array_init(8);
switch (subtlv->type) {
case PP2_SUBTYPE_SSL_VERSION:
array_set_key_value(hctx->env,

2
src/mod_magnet.c

@ -423,7 +423,7 @@ static int magnet_status_set(lua_State *L) {
static int magnet_status_pairs(lua_State *L) {
server *srv = magnet_get_server(L);
return magnet_array_pairs(L, srv->status);
return magnet_array_pairs(L, &srv->status);
}
typedef struct {

2
src/mod_maxminddb.c

@ -426,7 +426,7 @@ CONNECTION_FUNC(mod_maxminddb_request_env_handler)
array *env = con->plugin_ctx[p->id];
if (NULL == env) {
env = con->plugin_ctx[p->id] = array_init();
env = con->plugin_ctx[p->id] = array_init(pconf.env->used);
if (pconf.mmdb)
mod_maxmind_geoip2(env, &con->dst_addr, &pconf);
}

2
src/mod_openssl.c

@ -1576,7 +1576,7 @@ SETDEFAULTS_FUNC(mod_openssl_set_defaults)
plugin_data * const p = p_d;
p->srv = srv;
p->cafiles = array_init();
p->cafiles = array_init(0);
if (!config_plugin_values_init(srv, p, cpk, "mod_openssl"))
return HANDLER_ERROR;

4
src/mod_ssi.c

@ -64,8 +64,8 @@ INIT_FUNC(mod_ssi_init) {
p->timefmt = buffer_init();
p->stat_fn = buffer_init();
p->ssi_vars = array_init();
p->ssi_cgi_env = array_init();
p->ssi_vars = array_init(8);
p->ssi_cgi_env = array_init(32);
return p;
}

2
src/mod_status.c

@ -714,7 +714,7 @@ static handler_t mod_status_handle_server_status_json(server *srv, connection *c
static handler_t mod_status_handle_server_statistics(server *srv, connection *con) {
buffer *b;
size_t i;
array *st = srv->status;
array *st = &srv->status;
if (0 == st->used) {
/* we have nothing to send */

12
src/server.c

@ -242,12 +242,6 @@ static server *server_init(void) {
CLEAN(tmp_chunk_len);
#undef CLEAN
#define CLEAN(x) \
srv->x = array_init();
CLEAN(status);
#undef CLEAN
for (int i = 0; i < FILE_CACHE_MAX; ++i) {
srv->mtime_cache[i].mtime = (time_t)-1;
}
@ -293,11 +287,7 @@ static void server_free(server *srv) {
config_free(srv);
#define CLEAN(x) \
array_free(srv->x);
CLEAN(status);
#undef CLEAN
array_free_data(&srv->status);
free(srv->joblist.ptr);
free(srv->fdwaitqueue.ptr);

8
src/status_counter.h

@ -21,22 +21,22 @@ void status_counter_set(server *srv, const char *s, size_t len, int val);
__attribute_returns_nonnull__
static inline
int *status_counter_get_counter(server *srv, const char *s, size_t len) {
return array_get_int_ptr(srv->status, s, len);
return array_get_int_ptr(&srv->status, s, len);
}
static inline
void status_counter_inc(server *srv, const char *s, size_t len) {
++(*array_get_int_ptr(srv->status, s, len));
++(*array_get_int_ptr(&srv->status, s, len));
}
static inline
void status_counter_dec(server *srv, const char *s, size_t len) {
--(*array_get_int_ptr(srv->status, s, len));
--(*array_get_int_ptr(&srv->status, s, len));
}
static inline
void status_counter_set(server *srv, const char *s, size_t len, int val) {
*array_get_int_ptr(srv->status, s, len) = val;
*array_get_int_ptr(&srv->status, s, len) = val;
}

6
src/t/test_array.c

@ -11,7 +11,7 @@
static void test_array_get_int_ptr (void) {
data_integer *di;
int *i;
array *a = array_init();
array *a = array_init(0);
i = array_get_int_ptr(a, CONST_STR_LEN("abc"));
assert(NULL != i);
@ -30,7 +30,7 @@ static void test_array_get_int_ptr (void) {
static void test_array_insert_value (void) {
data_string *ds;
array *a = array_init();
array *a = array_init(0);
array_insert_value(a, CONST_STR_LEN("def"));
ds = (data_string *)a->data[0];
@ -42,7 +42,7 @@ static void test_array_insert_value (void) {
static void test_array_set_key_value (void) {
data_string *ds;
array *a = array_init();
array *a = array_init(0);
array_set_key_value(a, CONST_STR_LEN("abc"), CONST_STR_LEN("def"));
ds = (data_string *)array_get_element_klen(a, CONST_STR_LEN("does-not-exist"));

4
src/t/test_mod_access.c

@ -8,8 +8,8 @@
#include "mod_access.c"
static void test_mod_access_check(void) {
array *allow = array_init();
array *deny = array_init();
array *allow = array_init(0);
array *deny = array_init(0);
buffer *urlpath = buffer_init();
int lc = 0;

2
src/t/test_mod_evhost.c

@ -26,7 +26,7 @@ static void test_mod_evhost_build_doc_root_path_loop(struct ttt *tt, size_t nelt
static void test_mod_evhost_build_doc_root_path(void) {
buffer *authority = buffer_init();
buffer *b = buffer_init();
array *a = array_init();
array *a = array_init(0);
struct ttt tt1[] = { /* "host.example.org" */
/* correct pattern not using dot notation */
{ CONST_STR_LEN("/web/%3/"),

Loading…
Cancel
Save