From 0d2dd169fac48f09fb4fbea3268e06b61d4d0a0c Mon Sep 17 00:00:00 2001 From: Pavlo Yatsukhnenko Date: Mon, 18 Feb 2019 14:33:29 +0200 Subject: Use zend_string for storing key hashing algorithm --- redis_array_impl.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'redis_array_impl.c') diff --git a/redis_array_impl.c b/redis_array_impl.c index 918359c5..2c5b6d48 100644 --- a/redis_array_impl.c +++ b/redis_array_impl.c @@ -161,7 +161,7 @@ ra_find_name(const char *name) { /* laod array from INI settings */ RedisArray *ra_load_array(const char *name TSRMLS_DC) { - zval *z_data, z_fun, z_dist, z_algo; + zval *z_data, z_fun, z_dist; zval z_params_hosts; zval z_params_prev; zval z_params_funs; @@ -177,6 +177,7 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) { zval z_params_consistent; RedisArray *ra = NULL; + zend_string *algorithm= NULL; zend_bool b_index = 0, b_autorehash = 0, b_pconnect = 0, consistent = 0; long l_retry_interval = 0; zend_bool b_lazy_connect = 0; @@ -232,9 +233,8 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) { if ((iptr = INI_STR("redis.arrays.algorithm")) != NULL) { sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_algo TSRMLS_CC); } - ZVAL_NULL(&z_algo); if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_algo), name, name_len)) != NULL) { - ZVAL_ZVAL(&z_algo, z_data, 1, 0); + algorithm = zval_get_string(z_data); } /* find index option */ @@ -337,13 +337,15 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) { /* create RedisArray object */ - ra = ra_make_array(hHosts, &z_fun, &z_dist, &z_algo, hPrev, b_index, b_pconnect, l_retry_interval, b_lazy_connect, d_connect_timeout, read_timeout, consistent TSRMLS_CC); + ra = ra_make_array(hHosts, &z_fun, &z_dist, hPrev, b_index, b_pconnect, l_retry_interval, b_lazy_connect, d_connect_timeout, read_timeout, consistent, algorithm TSRMLS_CC); if (ra) { ra->auto_rehash = b_autorehash; if(ra->prev) ra->prev->auto_rehash = b_autorehash; } /* cleanup */ + if (algorithm) zend_string_release(algorithm); + zval_dtor(&z_params_hosts); zval_dtor(&z_params_prev); zval_dtor(&z_params_funs); @@ -357,7 +359,6 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) { zval_dtor(&z_params_read_timeout); zval_dtor(&z_params_lazy_connect); zval_dtor(&z_params_consistent); - zval_dtor(&z_algo); zval_dtor(&z_dist); zval_dtor(&z_fun); @@ -405,7 +406,7 @@ ra_make_continuum(zend_string **hosts, int nb_hosts) } RedisArray * -ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, zval *z_algo, HashTable *hosts_prev, zend_bool b_index, zend_bool b_pconnect, long retry_interval, zend_bool b_lazy_connect, double connect_timeout, double read_timeout, zend_bool consistent TSRMLS_DC) { +ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev, zend_bool b_index, zend_bool b_pconnect, long retry_interval, zend_bool b_lazy_connect, double connect_timeout, double read_timeout, zend_bool consistent, zend_string *algorithm TSRMLS_DC) { int i, count; RedisArray *ra; @@ -415,7 +416,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, zval *z_algo, HashTab /* create object */ ra = emalloc(sizeof(RedisArray)); ra->hosts = ecalloc(count, sizeof(*ra->hosts)); - ra->redis = ecalloc(count, sizeof(zval)); + ra->redis = ecalloc(count, sizeof(*ra->redis)); ra->count = 0; ra->z_multi_exec = NULL; ra->index = b_index; @@ -424,6 +425,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, zval *z_algo, HashTab ra->connect_timeout = connect_timeout; ra->read_timeout = read_timeout; ra->continuum = NULL; + ra->algorithm = NULL; if (ra_load_hosts(ra, hosts, retry_interval, b_lazy_connect TSRMLS_CC) == NULL || !ra->count) { for (i = 0; i < ra->count; ++i) { @@ -435,7 +437,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, zval *z_algo, HashTab efree(ra); return NULL; } - ra->prev = hosts_prev ? ra_make_array(hosts_prev, z_fun, z_dist, z_algo, NULL, b_index, b_pconnect, retry_interval, b_lazy_connect, connect_timeout, read_timeout, consistent TSRMLS_CC) : NULL; + ra->prev = hosts_prev ? ra_make_array(hosts_prev, z_fun, z_dist, NULL, b_index, b_pconnect, retry_interval, b_lazy_connect, connect_timeout, read_timeout, consistent, algorithm TSRMLS_CC) : NULL; /* init array data structures */ ra_init_function_table(ra); @@ -443,7 +445,7 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, zval *z_algo, HashTab /* Set hash function and distribtor if provided */ ZVAL_ZVAL(&ra->z_fun, z_fun, 1, 0); ZVAL_ZVAL(&ra->z_dist, z_dist, 1, 0); - ZVAL_ZVAL(&ra->z_algo, z_algo, 1, 0); + if (algorithm) ra->algorithm = zend_string_copy(algorithm); /* init continuum */ if (consistent) { @@ -537,7 +539,7 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D const php_hash_ops *ops; /* hash */ - if (Z_TYPE(ra->z_algo) == IS_STRING && (ops = php_hash_fetch_ops(Z_STRVAL(ra->z_algo), Z_STRLEN(ra->z_algo))) != NULL) { + if (ra->algorithm && (ops = php_hash_fetch_ops(ZSTR_VAL(ra->algorithm), ZSTR_LEN(ra->algorithm))) != NULL) { void *ctx = emalloc(ops->context_size); unsigned char *digest = emalloc(ops->digest_size); -- cgit v1.2.3