Browse Source

[core] const data_unset *array_get_element_klen()

return (const data_unset *) from array_get_element_klen();
use array_get_data_unset() for non-const (note: marked attribute cold)
master
Glenn Strauss 3 months ago
parent
commit
0045b9aa1a
  1. 2
      src/array.c
  2. 2
      src/array.h
  3. 8
      src/configfile-glue.c
  4. 4
      src/plugin_config.h
  5. 6
      src/server.c

2
src/array.c

@ -183,7 +183,7 @@ static int32_t array_get_index(const array * const a, const char * const k, cons
}
__attribute_hot__
data_unset *array_get_element_klen(const array * const a, const char *key, const uint32_t klen) {
const data_unset *array_get_element_klen(const array * const a, const char *key, const uint32_t klen) {
const int32_t ipos = array_get_index(a, key, klen);
return ipos >= 0 ? a->sorted[ipos] : NULL;
}

2
src/array.h

@ -95,7 +95,7 @@ __attribute_pure__
data_unset *array_get_element_klen_ext(const array *a, int ext, const char *key, uint32_t klen);
__attribute_pure__
data_unset *array_get_element_klen(const array *a, const char *key, uint32_t klen);
const data_unset *array_get_element_klen(const array *a, const char *key, uint32_t klen);
__attribute_cold__
__attribute_pure__

8
src/configfile-glue.c

@ -41,7 +41,7 @@ void config_get_config_cond_info(config_cond_info * const cfginfo, uint32_t idx)
cfginfo->op = dc->op;
}
int config_plugin_value_tobool (data_unset *du, int default_value)
int config_plugin_value_tobool (const data_unset *du, int default_value)
{
if (NULL == du) return default_value;
if (du->type == TYPE_STRING) {
@ -63,7 +63,7 @@ int config_plugin_value_tobool (data_unset *du, int default_value)
return default_value;
}
int32_t config_plugin_value_to_int32 (data_unset *du, int32_t default_value)
int32_t config_plugin_value_to_int32 (const data_unset *du, int32_t default_value)
{
if (NULL == du) return default_value;
if (du->type == TYPE_STRING) {
@ -86,7 +86,7 @@ int config_plugin_values_init_block(server * const srv, const array * const ca,
int rc = 1; /* default is success */
for (int i = 0; cpk[i].ktype != T_CONFIG_UNSET; ++i) {
data_unset * const du =
const data_unset * const du =
array_get_element_klen(ca, cpk[i].k, cpk[i].klen);
if (NULL == du) continue; /* not found */
@ -287,7 +287,7 @@ int config_plugin_values_init(server * const srv, void *p_d, const config_plugin
matches[n] = 0;
for (int i = 0; cpk[i].ktype != T_CONFIG_UNSET; ++i) {
data_unset * const du =
const data_unset * const du =
array_get_element_klen(ca, cpk[i].k, cpk[i].klen);
if (NULL == du) continue; /* not found */

4
src/plugin_config.h

@ -131,10 +131,10 @@ typedef struct {
} config_plugin_keys_t;
__attribute_cold__
int config_plugin_value_tobool(data_unset *du, int default_value);
int config_plugin_value_tobool(const data_unset *du, int default_value);
__attribute_cold__
int32_t config_plugin_value_to_int32 (data_unset *du, int32_t default_value);
int32_t config_plugin_value_to_int32 (const data_unset *du, int32_t default_value);
__attribute_cold__
int config_plugin_values_init_block(server * const srv, const array * const ca, const config_plugin_keys_t * const cpk, const char * const mname, config_plugin_value_t *cpv);

6
src/server.c

@ -793,8 +793,8 @@ static int server_graceful_state_bg (server *srv) {
/* check if server should fork and background (bg) itself
* to continue processing requests already in progress */
data_unset * const du =
array_get_element_klen(srv->srvconf.feature_flags,
CONST_STR_LEN("server.graceful-restart-bg"));
array_get_data_unset(srv->srvconf.feature_flags,
CONST_STR_LEN("server.graceful-restart-bg"));
if (!config_plugin_value_tobool(du, 0)) return 0;
/*(set flag to false to avoid repeating)*/
@ -931,7 +931,7 @@ static void server_graceful_state (server *srv) {
if (!srv_shutdown) {
if (0 == srv->graceful_expire_ts && srv->srvconf.feature_flags) {
data_unset * const du =
const data_unset * const du =
array_get_element_klen(srv->srvconf.feature_flags,
CONST_STR_LEN("server.graceful-shutdown-timeout"));
srv->graceful_expire_ts = config_plugin_value_to_int32(du, 0);

Loading…
Cancel
Save