@@ -412,6 +412,50 @@ ra_call_distributor(RedisArray *ra, const char *key, int key_len, int *pos TSRML
412412 return 1 ;
413413}
414414
415+ zend_bool
416+ ra_check_distributor (RedisArray * ra , int * num_original , int * num_reshards TSRMLS_DC ) {
417+ if (Z_TYPE_P (ra -> z_dist ) == IS_ARRAY ) {
418+ zval * * z_original_pp ;
419+ zval * * z_reshards_pp ;
420+ HashTable * shards = Z_ARRVAL_P (ra -> z_dist );
421+ if (zend_hash_num_elements (shards ) != 2 ) {
422+ return 0 ;
423+ }
424+ if (zend_hash_index_find (shards , 0 , (void * * )& z_original_pp ) != SUCCESS ||
425+ zend_hash_index_find (shards , 1 , (void * * )& z_reshards_pp ) != SUCCESS ) {
426+ return 0 ;
427+ }
428+ if (Z_TYPE_PP (z_original_pp ) == IS_LONG ) {
429+ if ((* num_original = Z_LVAL_PP (z_original_pp )) == 0 ) {
430+ return 0 ;
431+ }
432+ }
433+ else if (Z_TYPE_PP (z_original_pp ) == IS_STRING ) {
434+ if ((* num_original = atol (Z_STRVAL_PP (z_original_pp ))) == 0 ) {
435+ return 0 ;
436+ }
437+ }
438+ else {
439+ return 0 ;
440+ }
441+ if (Z_TYPE_PP (z_reshards_pp ) == IS_LONG ) {
442+ if ((* num_reshards = Z_LVAL_PP (z_reshards_pp )) == 0 ) {
443+ return 0 ;
444+ }
445+ }
446+ else if (Z_TYPE_PP (z_reshards_pp ) == IS_STRING ) {
447+ if ((* num_reshards = atol (Z_STRVAL_PP (z_reshards_pp ))) == 0 ) {
448+ return 0 ;
449+ }
450+ }
451+ else {
452+ return 0 ;
453+ }
454+ return 1 ;
455+ }
456+ return 0 ;
457+ }
458+
415459zval *
416460ra_find_node (RedisArray * ra , const char * key , int key_len , int * out_pos TSRMLS_DC ) {
417461
@@ -426,36 +470,8 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D
426470
427471 if (ra -> z_dist ) {
428472 char * error = NULL ;
429- if (Z_TYPE_P (ra -> z_dist ) == IS_ARRAY && !zend_is_callable_ex (ra -> z_dist , NULL , 0 , NULL , NULL , NULL , & error TSRMLS_CC )) {
430- int num_original , num_reshards ;
431- zval * * z_original_pp ;
432- zval * * z_reshards_pp ;
433- HashTable * shards = Z_ARRVAL_P (ra -> z_dist );
434- if (zend_hash_num_elements (shards ) != 2 ) {
435- return NULL ;
436- }
437- if (zend_hash_index_find (shards , 0 , (void * * )& z_original_pp ) != SUCCESS ||
438- zend_hash_index_find (shards , 1 , (void * * )& z_reshards_pp ) != SUCCESS ) {
439- return NULL ;
440- }
441- if (Z_TYPE_PP (z_original_pp ) == IS_LONG ) {
442- num_original = Z_LVAL_PP (z_original_pp );
443- }
444- else if (Z_TYPE_PP (z_original_pp ) == IS_STRING ) {
445- num_original = atol (Z_STRVAL_PP (z_original_pp ));
446- }
447- else {
448- return NULL ;
449- }
450- if (Z_TYPE_PP (z_reshards_pp ) == IS_LONG ) {
451- num_reshards = Z_LVAL_PP (z_reshards_pp );
452- }
453- else if (Z_TYPE_PP (z_reshards_pp ) == IS_STRING ) {
454- num_reshards = atol (Z_STRVAL_PP (z_reshards_pp ));
455- }
456- else {
457- return NULL ;
458- }
473+ int num_original , num_reshards ;
474+ if (ra_check_distributor (ra , & num_original , & num_reshards TSRMLS_CC )) {
459475 if (num_reshards < 1 || ra -> count != (num_original * (1 << num_reshards ))) {
460476 return NULL ;
461477 }
0 commit comments