Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2017-04-27 14:37:13 +0300
committerPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2017-04-27 17:46:49 +0300
commit47d3722dec9661b9820c2a9fae3f379998f64a6b (patch)
treee5b982c2c2e7a1d586ccaf398deab1e33163a159
parent9ec9aedea803ebc7b55fca026f3be69471d0e964 (diff)
Remove `ra_find_key` + use return_value instead of stack allocated z_tmp in`ra_forward_call`
-rw-r--r--redis_array.c22
-rw-r--r--redis_array_impl.c20
-rw-r--r--redis_array_impl.h1
3 files changed, 14 insertions, 29 deletions
diff --git a/redis_array.c b/redis_array.c
index 2cf2303d..ce3a6eb1 100644
--- a/redis_array.c
+++ b/redis_array.c
@@ -345,7 +345,7 @@ PHP_METHOD(RedisArray, __construct)
static void
ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, int cmd_len, zval *z_args, zval *z_new_target) {
- zval z_tmp, z_fun, *redis_inst, *z_callargs, *zp_tmp;
+ zval z_fun, *redis_inst, *z_callargs, *zp_tmp;
char *key = NULL; /* set to avoid "unused-but-set-variable" */
int i, key_len = 0, argc;
HashTable *h_args;
@@ -358,10 +358,12 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
redis_inst = ra->z_multi_exec; /* we already have the instance */
} else {
/* extract key and hash it. */
- if(!(key = ra_find_key(ra, z_args, cmd, &key_len))) {
+ if ((zp_tmp = zend_hash_index_find(h_args, 0)) == NULL || Z_TYPE_P(zp_tmp) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not find key");
RETURN_FALSE;
- }
+ }
+ key = Z_STRVAL_P(zp_tmp);
+ key_len = Z_STRLEN_P(zp_tmp);
/* find node */
redis_inst = ra_find_node(ra, key, key_len, NULL TSRMLS_CC);
@@ -371,9 +373,6 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
}
}
- /* check if write cmd */
- b_write_cmd = ra_is_write_cmd(ra, cmd, cmd_len);
-
/* pass call through */
ZVAL_STRINGL(&z_fun, cmd, cmd_len); /* method name */
z_callargs = ecalloc(argc + 1, sizeof(zval));
@@ -387,20 +386,23 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
/* multi/exec */
if(ra->z_multi_exec) {
- call_user_function(&redis_ce->function_table, ra->z_multi_exec, &z_fun, &z_tmp, argc, z_callargs);
+ call_user_function(&redis_ce->function_table, ra->z_multi_exec, &z_fun, return_value, argc, z_callargs);
+ zval_dtor(return_value);
zval_dtor(&z_fun);
- zval_dtor(&z_tmp);
efree(z_callargs);
RETURN_ZVAL(getThis(), 1, 0);
}
+ /* check if write cmd */
+ b_write_cmd = ra_is_write_cmd(ra, cmd, cmd_len);
+
/* CALL! */
if(ra->index && b_write_cmd) {
/* add MULTI + SADD */
ra_index_multi(redis_inst, MULTI TSRMLS_CC);
/* call using discarded temp value and extract exec results after. */
- call_user_function(&redis_ce->function_table, redis_inst, &z_fun, &z_tmp, argc, z_callargs);
- zval_dtor(&z_tmp);
+ call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs);
+ zval_dtor(return_value);
/* add keys to index. */
ra_index_key(key, key_len, redis_inst TSRMLS_CC);
diff --git a/redis_array_impl.c b/redis_array_impl.c
index 4918d814..2795491c 100644
--- a/redis_array_impl.c
+++ b/redis_array_impl.c
@@ -401,6 +401,7 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSR
return NULL;
}
+ ZVAL_NULL(&z_ret);
/* call extraction function */
ZVAL_STRINGL(&z_argv, key, key_len);
call_user_function(EG(function_table), NULL, &ra->z_fun, &z_ret, 1, &z_argv);
@@ -448,6 +449,7 @@ ra_call_distributor(RedisArray *ra, const char *key, int key_len, int *pos TSRML
return 0;
}
+ ZVAL_NULL(&z_ret);
/* call extraction function */
ZVAL_STRINGL(&z_argv, key, key_len);
call_user_function(EG(function_table), NULL, &ra->z_dist, &z_ret, 1, &z_argv);
@@ -513,24 +515,6 @@ ra_find_node_by_name(RedisArray *ra, const char *host, int host_len TSRMLS_DC) {
return NULL;
}
-
-char *
-ra_find_key(RedisArray *ra, zval *z_args, const char *cmd, int *key_len) {
-
- zval *zp_tmp;
- int key_pos = 0; /* TODO: change this depending on the command */
-
- if (zend_hash_num_elements(Z_ARRVAL_P(z_args)) == 0 ||
- (zp_tmp = zend_hash_index_find(Z_ARRVAL_P(z_args), key_pos)) == NULL ||
- Z_TYPE_P(zp_tmp) != IS_STRING
- ) {
- return NULL;
- }
-
- *key_len = Z_STRLEN_P(zp_tmp);
- return Z_STRVAL_P(zp_tmp);
-}
-
void
ra_index_multi(zval *z_redis, long multi_value TSRMLS_DC) {
diff --git a/redis_array_impl.h b/redis_array_impl.h
index 082dc172..385daadf 100644
--- a/redis_array_impl.h
+++ b/redis_array_impl.h
@@ -17,7 +17,6 @@ zval *ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TS
void ra_init_function_table(RedisArray *ra);
void ra_move_key(const char *key, int key_len, zval *z_from, zval *z_to TSRMLS_DC);
-char * ra_find_key(RedisArray *ra, zval *z_args, const char *cmd, int *key_len);
void ra_index_multi(zval *z_redis, long multi_value TSRMLS_DC);
void ra_index_key(const char *key, int key_len, zval *z_redis TSRMLS_DC);