Skip to content

Commit e102476

Browse files
committed
review: reduce memory allocation
1 parent 45aace1 commit e102476

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

agent/fw_drupal8.c

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,6 @@ NR_PHP_WRAPPER(nr_drupal94_invoke_all_with_clean) {
608608
NR_PHP_WRAPPER_END
609609
#endif // OAPI
610610

611-
#define NR_FREE_HOOK_MEM \
612-
nr_free(hook_str); \
613-
nr_free(class_str); \
614-
nr_free(method_str); \
615-
nr_free(module_str); \
616-
nr_free(hookpath);
617-
618611
/*
619612
* Purpose: Instrument Drupal Attribute Hooks for Drupal 11.1+
620613
*
@@ -634,10 +627,6 @@ static bool nr_drupal_hook_attribute_instrument(zval* module_handler) {
634627
zval* module_val = NULL;
635628
zend_ulong key_num = 0;
636629

637-
char* hook_str = NULL;
638-
char* class_str = NULL;
639-
char* method_str = NULL;
640-
char* module_str = NULL;
641630
char* hookpath = NULL;
642631

643632
hook_implementation_map = nr_php_get_zval_object_property(
@@ -651,7 +640,7 @@ static bool nr_drupal_hook_attribute_instrument(zval* module_handler) {
651640
nrl_warning(NRL_FRAMEWORK,
652641
"hookImplementationsMap[hook = %s]: invalid value",
653642
NRSAFESTR(ZEND_STRING_VALUE(hook_key)));
654-
NR_FREE_HOOK_MEM
643+
nr_free(hookpath);
655644
return false;
656645
}
657646

@@ -663,41 +652,38 @@ static bool nr_drupal_hook_attribute_instrument(zval* module_handler) {
663652
nrl_warning(NRL_FRAMEWORK,
664653
"hookImplementationsMap[class = %s]: invalid value",
665654
NRSAFESTR(ZEND_STRING_VALUE(class_key)));
666-
NR_FREE_HOOK_MEM
655+
nr_free(hookpath);
667656
return false;
668657
}
669658

670659
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(class_val), key_num, method_key,
671660
module_val) {
672661
(void)key_num;
673662

674-
NR_FREE_HOOK_MEM
675-
676663
if ((NULL == method_key)
677664
|| (0 == nr_php_is_zval_valid_string(module_val))) {
678665
nrl_warning(NRL_FRAMEWORK,
679666
"hookImplementationsMap[method = %s]: invalid value",
680667
NRSAFESTR(ZEND_STRING_VALUE(method_key)));
681-
NR_FREE_HOOK_MEM
668+
nr_free(hookpath);
682669
return false;
683670
}
684671

685-
hook_str = nr_strdup(ZEND_STRING_VALUE(hook_key));
686-
class_str = nr_strdup(ZEND_STRING_VALUE(class_key));
687-
method_str = nr_strdup(ZEND_STRING_VALUE(method_key));
688-
module_str = nr_strdup(Z_STRVAL_P(module_val));
689-
690672
if (0
691673
== nr_stricmp(ZEND_STRING_VALUE(class_key),
692674
"Drupal\\Core\\Extension\\ProceduralCall")) {
693-
hookpath = nr_formatf("%s", method_str);
675+
hookpath = nr_formatf("%s", ZEND_STRING_VALUE(method_key));
694676
} else {
695-
hookpath = nr_formatf("%s::%s", class_str, method_str);
677+
hookpath = nr_formatf("%s::%s", ZEND_STRING_VALUE(class_key),
678+
ZEND_STRING_VALUE(method_key));
696679
}
697680

698-
nr_php_wrap_user_function_drupal(hookpath, nr_strlen(hookpath),
699-
module_str, nr_strlen(module_str),
700-
hook_str, nr_strlen(hook_str));
681+
nr_php_wrap_user_function_drupal(
682+
hookpath, nr_strlen(hookpath), Z_STRVAL_P(module_val),
683+
Z_STRLEN_P(module_val), ZEND_STRING_VALUE(hook_key),
684+
ZEND_STRING_LEN(hook_key));
685+
686+
nr_free(hookpath);
701687
}
702688
ZEND_HASH_FOREACH_END();
703689
}
@@ -708,16 +694,13 @@ static bool nr_drupal_hook_attribute_instrument(zval* module_handler) {
708694
} else {
709695
nrl_warning(NRL_FRAMEWORK,
710696
"hookImplementationsMap property not a valid array");
711-
NR_FREE_HOOK_MEM
712697
return false;
713698
}
714699
} else {
715700
nrl_warning(NRL_FRAMEWORK, "NULL hookImplementationsMap object property");
716-
NR_FREE_HOOK_MEM
717701
return false;
718702
}
719703

720-
NR_FREE_HOOK_MEM
721704
return true;
722705
}
723706

0 commit comments

Comments
 (0)