@@ -358,6 +358,10 @@ static void nr_wordpress_call_user_func_array(zend_function* func,
358
358
nr_php_wrap_callable (func , nr_wordpress_wrap_hook TSRMLS_CC );
359
359
}
360
360
361
+ static void free_tag (void * tag ) {
362
+ nr_free (tag );
363
+ }
364
+
361
365
/*
362
366
* Some plugins generate transient tag names. We can detect these by checking
363
367
* the substrings returned from our regex rule. If the tag is transient, we
@@ -366,8 +370,7 @@ static void nr_wordpress_call_user_func_array(zend_function* func,
366
370
* Example: (old) add_option__transient_timeout_twccr_382402301f44c883bc0137_cat
367
371
* (new) add_option__transient_timeout_twccr_*_cat
368
372
*/
369
- static char * nr_wordpress_clean_tag (const zval * tag TSRMLS_DC ) {
370
- char * orig_tag = NULL ;
373
+ static char * nr_wordpress_clean_tag (const zval * tag ) {
371
374
char * clean_tag = NULL ;
372
375
nr_regex_t * regex = NULL ;
373
376
nr_regex_substrings_t * ss = NULL ;
@@ -381,8 +384,16 @@ static char* nr_wordpress_clean_tag(const zval* tag TSRMLS_DC) {
381
384
return NULL ;
382
385
}
383
386
384
- orig_tag = nr_strndup (Z_STRVAL_P (tag ), Z_STRLEN_P (tag ));
385
- ss = nr_regex_match_capture (regex , orig_tag , nr_strlen (orig_tag ));
387
+ if (NULL == NRPRG (wordpress_clean_tag_cache )) {
388
+ NRPRG (wordpress_clean_tag_cache ) = nr_hashmap_create (free_tag );
389
+ }
390
+
391
+ if (nr_hashmap_get_into (NRPRG (wordpress_clean_tag_cache ), Z_STRVAL_P (tag ),
392
+ Z_STRLEN_P (tag ), (void * * )& clean_tag )) {
393
+ return clean_tag ;
394
+ }
395
+
396
+ ss = nr_regex_match_capture (regex , Z_STRVAL_P (tag ), Z_STRLEN_P (tag ));
386
397
clean_tag = nr_regex_substrings_get (ss , 5 );
387
398
388
399
/*
@@ -403,7 +414,9 @@ static char* nr_wordpress_clean_tag(const zval* tag TSRMLS_DC) {
403
414
}
404
415
405
416
nr_regex_substrings_destroy (& ss );
406
- nr_free (orig_tag );
417
+
418
+ nr_hashmap_set (NRPRG (wordpress_clean_tag_cache ), Z_STRVAL_P (tag ),
419
+ Z_STRLEN_P (tag ), clean_tag );
407
420
408
421
return clean_tag ;
409
422
}
@@ -429,9 +442,8 @@ NR_PHP_WRAPPER(nr_wordpress_exec_handle_tag) {
429
442
430
443
NRPRG (check_cufa ) = true;
431
444
432
- NRPRG (wordpress_tag ) = nr_wordpress_clean_tag (tag TSRMLS_CC );
445
+ NRPRG (wordpress_tag ) = nr_wordpress_clean_tag (tag );
433
446
NR_PHP_WRAPPER_CALL ;
434
- nr_free (NRPRG (wordpress_tag ));
435
447
NRPRG (wordpress_tag ) = old_tag ;
436
448
if (NULL == NRPRG (wordpress_tag )) {
437
449
NRPRG (check_cufa ) = false;
@@ -517,10 +529,8 @@ NR_PHP_WRAPPER(nr_wordpress_apply_filters) {
517
529
518
530
NRPRG (check_cufa ) = true;
519
531
520
- NRPRG (wordpress_tag ) = nr_wordpress_clean_tag (tag TSRMLS_CC );
521
-
532
+ NRPRG (wordpress_tag ) = nr_wordpress_clean_tag (tag );
522
533
NR_PHP_WRAPPER_CALL ;
523
- nr_free (NRPRG (wordpress_tag ));
524
534
NRPRG (wordpress_tag ) = old_tag ;
525
535
if (NULL == NRPRG (wordpress_tag )) {
526
536
NRPRG (check_cufa ) = false;
0 commit comments