8000 refactoring · jrtkcoder/phpredis@495e5df · GitHub
[go: up one dir, main page]

Skip to content

Commit 495e5df

Browse files
committed
refactoring
1 parent ede4386 commit 495e5df

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

redis_array.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,6 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
358358
/* check if write cmd */
359359
b_write_cmd = ra_is_write_cmd(ra, cmd, cmd_len);
360360

361-
if(ra->index && b_write_cmd && !ra->z_multi_exec) { /* add MULTI + SADD */
362-
ra_index_multi(redis_inst, MULTI TSRMLS_CC);
363-
}
364-
365361
/* pass call through */
366362
ZVAL_STRINGL(&z_fun, cmd, cmd_len); /* method name */
367363
z_callargs = ecalloc(argc + 1, sizeof(zval));
@@ -384,6 +380,8 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
384380

385381
/* CALL! */
386382
if(ra->index && b_write_cmd) {
383+
/* add MULTI + SADD */
384+
ra_index_multi(redis_inst, MULTI TSRMLS_CC);
387385
/* call using discarded temp value and extract exec results after. */
388386
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, &z_tmp, argc, z_callargs);
389387
zval_dtor(&z_tmp);

redis_array_impl.c

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,10 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev
375375

376376
/* call userland key extraction function */
377377
char *
378-
ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS_DC) {
379-
380-
char *out;
381-
zval z_ret, z_argv[1];
378+
ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS_DC)
379+
{
380+
char *out = NULL;
381+
zval z_ret, z_argv;
382382

383383
/* check that we can call the extractor function */
384384
#if (PHP_MAJOR_VERSION < 7)
@@ -391,19 +391,15 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSR
391391
}
392392

393393
/* call extraction function */
394-
ZVAL_STRINGL(&z_argv[0], key, key_len);
395-
call_user_function(EG(function_table), NULL, &ra->z_fun, &z_ret, 1, z_argv);
396-
397-
if(Z_TYPE(z_ret) != IS_STRING) {
398-
zval_dtor(&z_argv[0]);
399-
zval_dtor(&z_ret);
400-
return NULL;
401-
}
394+
ZVAL_STRINGL(&z_argv, key, key_len);
395+
call_user_function(EG(function_table), NULL, &ra->z_fun, &z_ret, 1, &z_argv);
402396

403-
*out_len = Z_STRLEN(z_ret);
404-
out = estrndup(Z_STRVAL(z_ret), *out_len);
397+
if (Z_TYPE(z_ret) == IS_STRING) {
398+
*out_len = Z_STRLEN(z_ret);
399+
out = estrndup(Z_STRVAL(z_ret), *out_len);
400+
}
405401

406-
zval_dtor(&z_argv[0]);
402+
zval_dtor(&z_argv);
407403
zval_dtor(&z_ret);
408404
return out;
409405
}
@@ -426,10 +422,10 @@ ra_extract_key(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS
426422

427423
/* call userland key distributor function */
428424
zend_bool
429-
ra_call_distributor(RedisArray *ra, const char *key, int key_len, int *pos TSRMLS_DC) {
430-
431-
zval z_ret;
432-
zval z_argv[1];
425+
ra_call_distributor(RedisArray *ra, const char *key, int key_len, int *pos TSRMLS_DC)
426+
{
427+
zend_bool ret = 0;
428+
zval z_ret, z_argv;
433429

434430
/* check that we can call the extractor function */
435431
#if (PHP_MAJOR_VERSION < 7)
@@ -442,19 +438,17 @@ ra_call_distributor(RedisArray *ra, const char *key, int key_len, int *pos TSRML
442438
}
443439

444440
/* call extraction function */
445-
ZVAL_STRINGL(&z_argv[0], key, key_len);
446-
call_user_function(EG(function_table), NULL, &ra->z_dist, &z_ret, 1, z_argv);
441+
ZVAL_STRINGL(&z_argv, key, key_len);
442+
call_user_function(EG(function_table), NULL, &ra->z_dist, &z_ret, 1, &z_argv);
447443

448-
if(Z_TYPE(z_ret) != IS_LONG) {
449-
zval_dtor(&z_argv[0]);
450-
zval_dtor(&z_ret);
451-
return 0;
452-
}
444+
if (Z_TYPE(z_ret) == IS_LONG) {
445+
*pos = Z_LVAL(z_ret);
446+
ret = 1;
447+
}
453448

454-
*pos = Z_LVAL(z_ret);
455-
zval_dtor(&z_argv[0]);
449+
zval_dtor(&z_argv);
456450
zval_dtor(&z_ret);
457-
return 1;
451+
return ret;
458452
}
459453

460454
zval *

0 commit comments

Comments
 (0)
0