@@ -29,32 +29,30 @@ ZEND_TLS int lexbor_urls;
2929#define LEXBOR_MAX_URL_COUNT 500
3030#define LEXBOR_MRAW_BYTE_SIZE 8192
3131
32- #define ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str ) do { \
33- if (Z_TYPE_P(value) == IS_STRING && Z_STRLEN_P(value) > 0) { \
34- str.data = (lxb_char_t *) Z_STRVAL_P(value); \
35- str.length = Z_STRLEN_P(value); \
36- } else { \
37- ZEND_ASSERT(Z_ISNULL_P(value) || (Z_TYPE_P(value) == IS_STRING && Z_STRLEN_P(value) == 0)); \
38- str.data = (lxb_char_t *) ""; \
39- str.length = 0; \
40- } \
41- } while (0)
42-
43- #define ZVAL_LONG_OR_NULL_TO_LEXBOR_STR (value , str ) do { \
44- if (Z_TYPE_P(value) == IS_LONG) { \
45- ZVAL_STR(value, zend_long_to_str(Z_LVAL_P(value))); \
46- lexbor_str_init_append(&str, lexbor_parser->mraw, (const lxb_char_t *) Z_STRVAL_P(value), Z_STRLEN_P(value)); \
47- zval_ptr_dtor_str(value); \
48- } else { \
49- ZEND_ASSERT(Z_ISNULL_P(value)); \
50- str.data = (lxb_char_t *) ""; \
51- str.length = 0; \
52- } \
53- } while (0)
54-
55- #define LEXBOR_READ_ASCII_URI_COMPONENT (start , len , retval ) do { \
56- ZVAL_STRINGL(retval, (const char *) start, len); \
57- } while (0)
32+ static zend_always_inline void zval_string_or_null_to_lexbor_str (zval * value , lexbor_str_t * lexbor_str )
33+ {
34+ if (Z_TYPE_P (value ) == IS_STRING && Z_STRLEN_P (value ) > 0 ) {
35+ lexbor_str -> data = (lxb_char_t * ) Z_STRVAL_P (value );
36+ lexbor_str -> length = Z_STRLEN_P (value );
37+ } else {
38+ ZEND_ASSERT (Z_ISNULL_P (value ) || (Z_TYPE_P (value ) == IS_STRING && Z_STRLEN_P (value ) == 0 ));
39+ lexbor_str -> data = (lxb_char_t * ) "" ;
40+ lexbor_str -> length = 0 ;
41+ }
42+ }
43+
44+ static zend_always_inline void zval_long_or_null_to_lexbor_str (zval * value , lexbor_str_t * lexbor_str )
45+ {
46+ if (Z_TYPE_P (value ) == IS_LONG ) {
47+ ZVAL_STR (value , zend_long_to_str (Z_LVAL_P (value )));
48+ lexbor_str_init_append (lexbor_str , lexbor_parser -> mraw , (const lxb_char_t * ) Z_STRVAL_P (value ), Z_STRLEN_P (value ));
49+ zval_ptr_dtor_str (value );
50+ } else {
51+ ZEND_ASSERT (Z_ISNULL_P (value ));
52+ lexbor_str -> data = (lxb_char_t * ) "" ;
53+ lexbor_str -> length = 0 ;
54+ }
55+ }
5856
5957static void lexbor_cleanup_parser (void )
6058{
@@ -254,7 +252,7 @@ static zend_result lexbor_write_scheme(struct uri_internal_t *internal_uri, zval
254252 lxb_url_t * lexbor_uri = internal_uri -> uri ;
255253 lexbor_str_t str = {0 };
256254
257- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
255+ zval_string_or_null_to_lexbor_str (value , & str );
258256
259257 if (lxb_url_api_protocol_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
260258 fill_errors (errors );
@@ -270,7 +268,7 @@ static zend_result lexbor_read_username(const struct uri_internal_t *internal_ur
270268 lxb_url_t * lexbor_uri = internal_uri -> uri ;
271269
272270 if (lexbor_uri -> username .length ) {
273- LEXBOR_READ_ASCII_URI_COMPONENT ( lexbor_uri -> username .data , lexbor_uri -> username .length , retval );
271+ ZVAL_STRINGL ( retval , ( const char * ) lexbor_uri -> username .data , lexbor_uri -> username .length );
274272 } else {
275273 ZVAL_NULL (retval );
276274 }
@@ -283,7 +281,7 @@ static zend_result lexbor_write_username(uri_internal_t *internal_uri, zval *val
283281 lxb_url_t * lexbor_uri = internal_uri -> uri ;
284282 lexbor_str_t str = {0 };
285283
286- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
284+ zval_string_or_null_to_lexbor_str (value , & str );
287285
288286 if (lxb_url_api_username_set (lexbor_uri , str .data , str .length ) != LXB_STATUS_OK ) {
289287 fill_errors (errors );
@@ -299,7 +297,7 @@ static zend_result lexbor_read_password(const struct uri_internal_t *internal_ur
299297 lxb_url_t * lexbor_uri = internal_uri -> uri ;
300298
301299 if (lexbor_uri -> password .length > 0 ) {
302- LEXBOR_READ_ASCII_URI_COMPONENT ( lexbor_uri -> password .data , lexbor_uri -> password .length , retval );
300+ ZVAL_STRINGL ( retval , ( const char * ) lexbor_uri -> password .data , lexbor_uri -> password .length );
303301 } else {
304302 ZVAL_NULL (retval );
305303 }
@@ -312,7 +310,7 @@ static zend_result lexbor_write_password(struct uri_internal_t *internal_uri, zv
312310 lxb_url_t * lexbor_uri = internal_uri -> uri ;
313311 lexbor_str_t str = {0 };
314312
315- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
313+ zval_string_or_null_to_lexbor_str (value , & str );
316314
317315 if (lxb_url_api_password_set (lexbor_uri , str .data , str .length ) != LXB_STATUS_OK ) {
318316 fill_errors (errors );
@@ -384,7 +382,7 @@ static zend_result lexbor_write_host(struct uri_internal_t *internal_uri, zval *
384382 lxb_url_t * lexbor_uri = internal_uri -> uri ;
385383 lexbor_str_t str = {0 };
386384
387- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
385+ zval_string_or_null_to_lexbor_str (value , & str );
388386
389387 if (lxb_url_api_hostname_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
390388 fill_errors (errors );
@@ -413,7 +411,7 @@ static zend_result lexbor_write_port(struct uri_internal_t *internal_uri, zval *
413411 lxb_url_t * lexbor_uri = internal_uri -> uri ;
414412 lexbor_str_t str = {0 };
415413
416- ZVAL_LONG_OR_NULL_TO_LEXBOR_STR (value , str );
414+ zval_long_or_null_to_lexbor_str (value , & str );
417415
418416 if (lxb_url_api_port_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
419417 fill_errors (errors );
@@ -429,7 +427,7 @@ static zend_result lexbor_read_path(const struct uri_internal_t *internal_uri, u
429427 lxb_url_t * lexbor_uri = internal_uri -> uri ;
430428
431429 if (lexbor_uri -> path .str .length ) {
432- LEXBOR_READ_ASCII_URI_COMPONENT ( lexbor_uri -> path .str .data , lexbor_uri -> path .str .length , retval );
430+ ZVAL_STRINGL ( retval , ( const char * ) lexbor_uri -> path .str .data , lexbor_uri -> path .str .length );
433431 } else {
434432 ZVAL_EMPTY_STRING (retval );
435433 }
@@ -442,7 +440,7 @@ static zend_result lexbor_write_path(struct uri_internal_t *internal_uri, zval *
442440 lxb_url_t * lexbor_uri = internal_uri -> uri ;
443441 lexbor_str_t str = {0 };
444442
445- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
443+ zval_string_or_null_to_lexbor_str (value , & str );
446444
447445 if (lxb_url_api_pathname_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
448446 fill_errors (errors );
@@ -458,7 +456,7 @@ static zend_result lexbor_read_query(const struct uri_internal_t *internal_uri,
458456 lxb_url_t * lexbor_uri = internal_uri -> uri ;
459457
460458 if (lexbor_uri -> query .length ) {
461- LEXBOR_READ_ASCII_URI_COMPONENT ( lexbor_uri -> query .data , lexbor_uri -> query .length , retval );
459+ ZVAL_STRINGL ( retval , ( const char * ) lexbor_uri -> query .data , lexbor_uri -> query .length );
462460 } else {
463461 ZVAL_NULL (retval );
464462 }
@@ -471,7 +469,7 @@ static zend_result lexbor_write_query(struct uri_internal_t *internal_uri, zval
471469 lxb_url_t * lexbor_uri = internal_uri -> uri ;
472470 lexbor_str_t str = {0 };
473471
474- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
472+ zval_string_or_null_to_lexbor_str (value , & str );
475473
476474 if ( lxb_url_api_search_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
477475 fill_errors (errors );
@@ -487,7 +485,7 @@ static zend_result lexbor_read_fragment(const struct uri_internal_t *internal_ur
487485 lxb_url_t * lexbor_uri = internal_uri -> uri ;
488486
489487 if (lexbor_uri -> fragment .length ) {
490- LEXBOR_READ_ASCII_URI_COMPONENT ( lexbor_uri -> fragment .data , lexbor_uri -> fragment .length , retval );
488+ ZVAL_STRINGL ( retval , ( const char * ) lexbor_uri -> fragment .data , lexbor_uri -> fragment .length );
491489 } else {
492490 ZVAL_NULL (retval );
493491 }
@@ -500,7 +498,7 @@ static zend_result lexbor_write_fragment(struct uri_internal_t *internal_uri, zv
500498 lxb_url_t * lexbor_uri = internal_uri -> uri ;
501499 lexbor_str_t str = {0 };
502500
503- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
501+ zval_string_or_null_to_lexbor_str (value , & str );
504502
505503 if (lxb_url_api_hash_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
506504 fill_errors (errors );
0 commit comments