mirror of
https://github.com/phpredis/phpredis.git
synced 2026-06-19 07:35:31 +00:00
Experimental: Integrate a pure C port of fast_float
Repo: https://github.com/kolemannix/ffc.h
This commit is contained in:
+13
-4
@@ -6,6 +6,8 @@
|
||||
#include "crc16.h"
|
||||
#include <zend_exceptions.h>
|
||||
|
||||
#include "ffc.h"
|
||||
|
||||
extern zend_class_entry *redis_cluster_exception_ce;
|
||||
int le_cluster_slot_cache;
|
||||
|
||||
@@ -1773,7 +1775,7 @@ PHP_REDIS_API void cluster_dbl_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
|
||||
}
|
||||
|
||||
// Convert to double, free response
|
||||
dbl = atof(resp);
|
||||
dbl = ffc_parse_double_simple(c->reply_len, resp, NULL);
|
||||
efree(resp);
|
||||
|
||||
CLUSTER_RETURN_DOUBLE(c, dbl);
|
||||
@@ -2935,13 +2937,15 @@ cluster_mbulk_assoc_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
|
||||
static int mbulk_resp_loop_dbl(RedisSock *redis_sock, zval *z_result,
|
||||
long long count, void *ctx)
|
||||
{
|
||||
char *line;
|
||||
int line_len;
|
||||
double dval;
|
||||
char *line;
|
||||
|
||||
while (count--) {
|
||||
line = redis_sock_read(redis_sock, &line_len);
|
||||
if (line != NULL) {
|
||||
add_next_index_double(z_result, atof(line));
|
||||
dval = ffc_parse_double_simple(line_len, line, NULL);
|
||||
add_next_index_double(z_result, dval);
|
||||
efree(line);
|
||||
} else {
|
||||
add_next_index_bool(z_result, 0);
|
||||
@@ -3041,6 +3045,7 @@ static int mbulk_resp_loop_zipdbl(RedisSock *redis_sock, zval *z_result,
|
||||
char *line, *key = NULL;
|
||||
int line_len, key_len = 0;
|
||||
long long idx = 0;
|
||||
double dval;
|
||||
|
||||
// Our context will need to be divisible by 2
|
||||
if (count %2 != 0) {
|
||||
@@ -3058,7 +3063,11 @@ static int mbulk_resp_loop_zipdbl(RedisSock *redis_sock, zval *z_result,
|
||||
zval zv, *z = &zv;
|
||||
redis_unpack(redis_sock,key,key_len, z);
|
||||
zend_string *tmp, *zstr = zval_get_tmp_string(z, &tmp);
|
||||
add_assoc_double_ex(z_result, ZSTR_VAL(zstr), ZSTR_LEN(zstr), atof(line));
|
||||
dval = ffc_parse_double_simple(ZSTR_LEN(zstr), ZSTR_VAL(zstr),
|
||||
NULL);
|
||||
add_assoc_double_ex(z_result, ZSTR_VAL(zstr), ZSTR_LEN(zstr),
|
||||
dval);
|
||||
|
||||
zend_tmp_string_release(tmp);
|
||||
zval_ptr_dtor_nogc(z);
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#include "php_network.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#define FFC_IMPL
|
||||
#include "ffc.h"
|
||||
|
||||
#ifdef HAVE_REDIS_IGBINARY
|
||||
#include "igbinary/igbinary.h"
|
||||
#endif
|
||||
@@ -1241,7 +1244,7 @@ redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
ret = atof(response);
|
||||
ret = ffc_parse_double_simple(response_len, response, NULL);
|
||||
efree(response);
|
||||
if (IS_ATOMIC(redis_sock)) {
|
||||
RETVAL_DOUBLE(ret);
|
||||
@@ -1729,6 +1732,7 @@ static void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab,
|
||||
HashTable *keytable = Z_ARRVAL_P(z_tab);
|
||||
zend_string *hkey, *tmp;
|
||||
zval z_ret, z_sub;
|
||||
double dval;
|
||||
|
||||
array_init_size(&z_ret, zend_hash_num_elements(keytable) / 2);
|
||||
|
||||
@@ -1755,17 +1759,21 @@ static void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab,
|
||||
}
|
||||
|
||||
/* get current value, a hash value now. */
|
||||
char *hval = Z_STRVAL_P(z_value_p);
|
||||
//char *hval = Z_STRVAL_P(z_value_p);
|
||||
zend_string *hval = zval_get_tmp_string(z_value_p, &tmp);
|
||||
|
||||
/* Decode the score depending on flag */
|
||||
if (decode == SCORE_DECODE_INT && Z_STRLEN_P(z_value_p) > 0) {
|
||||
ZVAL_LONG(&z_sub, atoi(hval+1));
|
||||
if (decode == SCORE_DECODE_INT && ZSTR_LEN(hval) > 0) {
|
||||
ZVAL_LONG(&z_sub, atoi(ZSTR_VAL(hval)+1));
|
||||
} else if (decode == SCORE_DECODE_DOUBLE) {
|
||||
ZVAL_DOUBLE(&z_sub, atof(hval));
|
||||
dval = ffc_parse_double_simple(ZSTR_LEN(hval), ZSTR_VAL(hval), NULL);
|
||||
ZVAL_DOUBLE(&z_sub, dval);
|
||||
} else {
|
||||
ZVAL_ZVAL(&z_sub, z_value_p, 1, 0);
|
||||
}
|
||||
|
||||
zend_tmp_string_release(tmp);
|
||||
|
||||
zend_symtable_update(Z_ARRVAL_P(&z_ret), hkey, &z_sub);
|
||||
|
||||
zend_tmp_string_release(tmp);
|
||||
@@ -3729,6 +3737,7 @@ redis_mbulk_reply_double(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zv
|
||||
char *line;
|
||||
int i, numElems, len;
|
||||
zval z_multi_result;
|
||||
double dval;
|
||||
|
||||
if (read_mbulk_header(redis_sock, &numElems) < 0) {
|
||||
REDIS_RESPONSE_ERROR(redis_sock, z_tab);
|
||||
@@ -3744,7 +3753,8 @@ redis_mbulk_reply_double(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zv
|
||||
add_next_index_bool(&z_multi_result, 0);
|
||||
continue;
|
||||
}
|
||||
add_next_index_double(&z_multi_result, atof(line));
|
||||
dval = ffc_parse_double_simple(len, line, NULL);
|
||||
add_next_index_double(&z_multi_result, dval);
|
||||
efree(line);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user