@@ -29,32 +29,30 @@ ZEND_TLS int lexbor_urls;
29
29
#define LEXBOR_MAX_URL_COUNT 500
30
30
#define LEXBOR_MRAW_BYTE_SIZE 8192
31
31
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
+ }
58
56
59
57
static void lexbor_cleanup_parser (void )
60
58
{
@@ -254,7 +252,7 @@ static zend_result lexbor_write_scheme(struct uri_internal_t *internal_uri, zval
254
252
lxb_url_t * lexbor_uri = internal_uri -> uri ;
255
253
lexbor_str_t str = {0 };
256
254
257
- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
255
+ zval_string_or_null_to_lexbor_str (value , & str );
258
256
259
257
if (lxb_url_api_protocol_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
260
258
fill_errors (errors );
@@ -270,7 +268,7 @@ static zend_result lexbor_read_username(const struct uri_internal_t *internal_ur
270
268
lxb_url_t * lexbor_uri = internal_uri -> uri ;
271
269
272
270
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 );
274
272
} else {
275
273
ZVAL_NULL (retval );
276
274
}
@@ -283,7 +281,7 @@ static zend_result lexbor_write_username(uri_internal_t *internal_uri, zval *val
283
281
lxb_url_t * lexbor_uri = internal_uri -> uri ;
284
282
lexbor_str_t str = {0 };
285
283
286
- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
284
+ zval_string_or_null_to_lexbor_str (value , & str );
287
285
288
286
if (lxb_url_api_username_set (lexbor_uri , str .data , str .length ) != LXB_STATUS_OK ) {
289
287
fill_errors (errors );
@@ -299,7 +297,7 @@ static zend_result lexbor_read_password(const struct uri_internal_t *internal_ur
299
297
lxb_url_t * lexbor_uri = internal_uri -> uri ;
300
298
301
299
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 );
303
301
} else {
304
302
ZVAL_NULL (retval );
305
303
}
@@ -312,7 +310,7 @@ static zend_result lexbor_write_password(struct uri_internal_t *internal_uri, zv
312
310
lxb_url_t * lexbor_uri = internal_uri -> uri ;
313
311
lexbor_str_t str = {0 };
314
312
315
- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
313
+ zval_string_or_null_to_lexbor_str (value , & str );
316
314
317
315
if (lxb_url_api_password_set (lexbor_uri , str .data , str .length ) != LXB_STATUS_OK ) {
318
316
fill_errors (errors );
@@ -384,7 +382,7 @@ static zend_result lexbor_write_host(struct uri_internal_t *internal_uri, zval *
384
382
lxb_url_t * lexbor_uri = internal_uri -> uri ;
385
383
lexbor_str_t str = {0 };
386
384
387
- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
385
+ zval_string_or_null_to_lexbor_str (value , & str );
388
386
389
387
if (lxb_url_api_hostname_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
390
388
fill_errors (errors );
@@ -413,7 +411,7 @@ static zend_result lexbor_write_port(struct uri_internal_t *internal_uri, zval *
413
411
lxb_url_t * lexbor_uri = internal_uri -> uri ;
414
412
lexbor_str_t str = {0 };
415
413
416
- ZVAL_LONG_OR_NULL_TO_LEXBOR_STR (value , str );
414
+ zval_long_or_null_to_lexbor_str (value , & str );
417
415
418
416
if (lxb_url_api_port_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
419
417
fill_errors (errors );
@@ -429,7 +427,7 @@ static zend_result lexbor_read_path(const struct uri_internal_t *internal_uri, u
429
427
lxb_url_t * lexbor_uri = internal_uri -> uri ;
430
428
431
429
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 );
433
431
} else {
434
432
ZVAL_EMPTY_STRING (retval );
435
433
}
@@ -442,7 +440,7 @@ static zend_result lexbor_write_path(struct uri_internal_t *internal_uri, zval *
442
440
lxb_url_t * lexbor_uri = internal_uri -> uri ;
443
441
lexbor_str_t str = {0 };
444
442
445
- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
443
+ zval_string_or_null_to_lexbor_str (value , & str );
446
444
447
445
if (lxb_url_api_pathname_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
448
446
fill_errors (errors );
@@ -458,7 +456,7 @@ static zend_result lexbor_read_query(const struct uri_internal_t *internal_uri,
458
456
lxb_url_t * lexbor_uri = internal_uri -> uri ;
459
457
460
458
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 );
462
460
} else {
463
461
ZVAL_NULL (retval );
464
462
}
@@ -471,7 +469,7 @@ static zend_result lexbor_write_query(struct uri_internal_t *internal_uri, zval
471
469
lxb_url_t * lexbor_uri = internal_uri -> uri ;
472
470
lexbor_str_t str = {0 };
473
471
474
- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
472
+ zval_string_or_null_to_lexbor_str (value , & str );
475
473
476
474
if ( lxb_url_api_search_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
477
475
fill_errors (errors );
@@ -487,7 +485,7 @@ static zend_result lexbor_read_fragment(const struct uri_internal_t *internal_ur
487
485
lxb_url_t * lexbor_uri = internal_uri -> uri ;
488
486
489
487
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 );
491
489
} else {
492
490
ZVAL_NULL (retval );
493
491
}
@@ -500,7 +498,7 @@ static zend_result lexbor_write_fragment(struct uri_internal_t *internal_uri, zv
500
498
lxb_url_t * lexbor_uri = internal_uri -> uri ;
501
499
lexbor_str_t str = {0 };
502
500
503
- ZVAL_STRING_OR_NULL_TO_LEXBOR_STR (value , str );
501
+ zval_string_or_null_to_lexbor_str (value , & str );
504
502
505
503
if (lxb_url_api_hash_set (lexbor_uri , lexbor_parser , str .data , str .length ) != LXB_STATUS_OK ) {
506
504
fill_errors (errors );
0 commit comments