@@ -34,7 +34,7 @@ zend_string_alloc(size_t len, int persistent)
3434 zend_string * zstr = emalloc (sizeof (* zstr ) + len + 1 );
3535
3636 ZSTR_VAL (zstr ) = (char * )zstr + sizeof (* zstr );
37- zstr -> len = len ;
37+ ZSTR_LEN ( zstr ) = len ;
3838 zstr -> gc = 0x01 ;
3939 return zstr ;
4040}
@@ -49,6 +49,25 @@ zend_string_init(const char *str, size_t len, int persistent)
4949 return zstr ;
5050}
5151
52+ static zend_always_inline zend_string *
53+ zend_string_realloc (zend_string * s , size_t len , int persistent )
54+ {
55+ zend_string * zstr ;
56+
57+ if (!s -> gc ) {
58+ zstr = zend_string_init (ZSTR_VAL (s ), len , 0 );
59+ } else if (s -> gc & 0x10 ) {
60+ ZSTR_VAL (s ) = erealloc (ZSTR_VAL (s ), len + 1 );
61+ ZSTR_LEN (s ) = len ;
62+ zstr = s ;
63+ } else {
64+ zstr = erealloc (s , sizeof (* zstr ) + len + 1 );
65+ ZSTR_VAL (zstr ) = (char * )zstr + sizeof (* zstr );
66+ ZSTR_LEN (zstr ) = len ;
67+ }
68+ return zstr ;
69+ }
70+
5271#define zend_string_equal_val (s1 , s2 ) !memcmp(ZSTR_VAL(s1), ZSTR_VAL(s2), ZSTR_LEN(s1))
5372#define zend_string_equal_content (s1 , s2 ) (ZSTR_LEN(s1) == ZSTR_LEN(s2) && zend_string_equal_val(s1, s2))
5473#define zend_string_equals (s1 , s2 ) (s1 == s2 || zend_string_equal_content(s1, s2))
@@ -533,14 +552,12 @@ typedef enum _PUBSUB_TYPE {
533552
534553#define PIPELINE_ENQUEUE_COMMAND (cmd , cmd_len ) do { \
535554 if (redis_sock->pipeline_cmd == NULL) { \
536- redis_sock->pipeline_cmd = estrndup (cmd, cmd_len); \
555+ redis_sock->pipeline_cmd = zend_string_init (cmd, cmd_len, 0 ); \
537556 } else { \
538- redis_sock->pipeline_cmd = erealloc(redis_sock->pipeline_cmd, \
539- redis_sock->pipeline_len + cmd_len); \
540- memcpy(&redis_sock->pipeline_cmd[redis_sock->pipeline_len], \
541- cmd, cmd_len); \
557+ size_t pipeline_len = ZSTR_LEN(redis_sock->pipeline_cmd); \
558+ redis_sock->pipeline_cmd = zend_string_realloc(redis_sock->pipeline_cmd, pipeline_len + cmd_len, 0); \
559+ memcpy(&ZSTR_VAL(redis_sock->pipeline_cmd)[pipeline_len], cmd, cmd_len); \
542560 } \
543- redis_sock->pipeline_len += cmd_len; \
544561} while (0)
545562
546563#define SOCKET_WRITE_COMMAND (redis_sock , cmd , cmd_len ) \
@@ -675,8 +692,7 @@ typedef struct {
675692 fold_item * head ;
676693 fold_item * current ;
677694
678- char * pipeline_cmd ;
679- size_t pipeline_len ;
695+ zend_string * pipeline_cmd ;
680696
681697 zend_string * err ;
682698
0 commit comments