Thanks to visit codestin.com
Credit goes to github.com

Skip to content

integer_length optimization #924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions library.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,18 +556,20 @@ void add_constant_long(zend_class_entry *ce, char *name, int value) {

int
integer_length(int i) {
int sz = 0;
int ci = abs(i);
while (ci > 0) {
ci /= 10;
int sz = 1;

if (i < 0) { /* allow for neg sign as well. */
i = -i;
sz++;
}
if (i == 0) { /* log 0 doesn't make sense. */
sz = 1;
} else if (i < 0) { /* allow for neg sign as well. */
sz++;
for (;;) {
if (i < 10) return sz;
if (i < 100) return sz + 1;
if (i < 1000) return sz + 2;
// Skip ahead by 4 orders of magnitude
i /= 10000U;
sz += 4;
}
return sz;
}

int
Expand Down
34 changes: 8 additions & 26 deletions redis_array_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,17 +425,11 @@ ra_extract_key(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS
char *start, *end;
*out_len = key_len;

if(ra->z_fun)
if(ra->z_fun) {
return ra_call_extractor(ra, key, key_len, out_len TSRMLS_CC);

/* look for '{' */
start = strchr(key, '{');
if(!start) return estrndup(key, key_len);

/* look for '}' */
end = strchr(start + 1, '}');
if(!end) return estrndup(key, key_len);

} else if ((start = strchr(key, '{')) == NULL || (end = strchr(start + 1, '}')) == NULL) {
return estrndup(key, key_len);
}
/* found substring */
*out_len = end - start - 1;
return estrndup(start + 1, *out_len);
Expand Down Expand Up @@ -768,17 +762,6 @@ ra_rehash_scan(zval *z_redis, char ***keys, int **key_lens, const char *cmd, con
return count;
}

static long
ra_rehash_scan_index(zval *z_redis, char ***keys, int **key_lens TSRMLS_DC) {
return ra_rehash_scan(z_redis, keys, key_lens, "SMEMBERS", PHPREDIS_INDEX_NAME TSRMLS_CC);
}

/* list keys using KEYS command */
static long
ra_rehash_scan_keys(zval *z_redis, char ***keys, int **key_lens TSRMLS_DC) {
return ra_rehash_scan(z_redis, keys, key_lens, "KEYS", "*" TSRMLS_CC);
}

/* run TYPE to find the type */
static zend_bool
ra_get_key_type(zval *z_redis, const char *key, int key_len, zval *z_from, long *res TSRMLS_DC) {
Expand Down Expand Up @@ -1254,9 +1237,9 @@ ra_rehash_server(RedisArray *ra, zval *z_redis, const char *hostname, zend_bool

/* list all keys */
if(b_index) {
count = ra_rehash_scan_index(z_redis, &keys, &key_lens TSRMLS_CC);
count = ra_rehash_scan(z_redis, &keys, &key_lens, "SMEMBERS", PHPREDIS_INDEX_NAME TSRMLS_CC);
} else {
count = ra_rehash_scan_keys(z_redis, &keys, &key_lens TSRMLS_CC);
count = ra_rehash_scan(z_redis, &keys, &key_lens, "KEYS", "*" TSRMLS_CC);
}

/* callback */
Expand All @@ -1274,12 +1257,11 @@ ra_rehash_server(RedisArray *ra, zval *z_redis, const char *hostname, zend_bool
/* php_printf("move [%s] from [%s] to [%s]\n", keys[i], hostname, ra->hosts[target_pos]); */
ra_move_key(keys[i], key_lens[i], z_redis, z_target TSRMLS_CC);
}
}

/* cleanup */
for(i = 0; i < count; ++i) {
/* cleanup */
efree(keys[i]);
}

efree(keys);
efree(key_lens);
}
Expand Down
2 changes: 1 addition & 1 deletion redis_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -3309,4 +3309,4 @@ void redis_unserialize_handler(INTERNAL_FUNCTION_PARAMETERS,
}
}

/* vim: set tabstop=4 softtabstops=4 noexpandtab shiftwidth=4: */
/* vim: set tabstop=4 softtabstop=4 expandtab shiftwidth=4: */
2 changes: 0 additions & 2 deletions redis_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
+----------------------------------------------------------------------+
*/

#include "common.h"

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
Expand Down