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-10-19 16:11:26 +0300
committerPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2017-10-19 16:11:31 +0300
commit621afa6c6d9f0d71a68361e7ae40c75fce1fa382 (patch)
tree1dc42f214361d4d85bb3ca16403ecfc54191f811 /redis_array_impl.c
parent1519cb586add370e7f5a2e8b368da8960b4a7294 (diff)
Refactor ra_extract_key
We don't need to copy extracted key part since we don't change it.
Diffstat (limited to 'redis_array_impl.c')
-rw-r--r--redis_array_impl.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/redis_array_impl.c b/redis_array_impl.c
index 1a5aa7ba..4a60fdde 100644
--- a/redis_array_impl.c
+++ b/redis_array_impl.c
@@ -401,7 +401,7 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSR
if (Z_TYPE(z_ret) == IS_STRING) {
*out_len = Z_STRLEN(z_ret);
- out = estrndup(Z_STRVAL(z_ret), *out_len);
+ out = Z_STRVAL(z_ret);
}
zval_dtor(&z_argv);
@@ -418,11 +418,11 @@ ra_extract_key(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS
if (Z_TYPE(ra->z_fun) != IS_NULL) {
return ra_call_extractor(ra, key, key_len, out_len TSRMLS_CC);
} else if ((start = strchr(key, '{')) == NULL || (end = strchr(start + 1, '}')) == NULL) {
- return estrndup(key, key_len);
+ return (char *)key;
}
/* found substring */
*out_len = end - start - 1;
- return estrndup(start + 1, *out_len);
+ return start + 1;
}
/* call userland key distributor function */
@@ -461,13 +461,13 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D
int pos, out_len;
/* extract relevant part of the key */
- out = ra_extract_key(ra, key, key_len, &out_len TSRMLS_CC);
- if(!out) return NULL;
+ if ((out = ra_extract_key(ra, key, key_len, &out_len TSRMLS_CC)) == NULL) {
+ return NULL;
+ }
if (Z_TYPE(ra->z_dist) != IS_NULL) {
pos = ra_call_distributor(ra, key, key_len TSRMLS_CC);
if (pos < 0 || pos >= ra->count) {
- efree(out);
return NULL;
}
} else {
@@ -483,7 +483,6 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D
/* get position on ring */
pos = (int)(hash * ra->count / 0xffffffff);
}
- efree(out);
if(out_pos) *out_pos = pos;