Skip to content

Commit 3ded06d

Browse files
committed
review: reduce memory allocation
1 parent efc0c4e commit 3ded06d

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
@@ -605,13 +605,6 @@ NR_PHP_WRAPPER(nr_drupal94_invoke_all_with_clean) {
605605
NR_PHP_WRAPPER_END
606606
#endif // OAPI
607607

608-
#define NR_FREE_HOOK_MEM \
609-
nr_free(hook_str); \
610-
nr_free(class_str); \
611-
nr_free(method_str); \
612-
nr_free(module_str); \
613-
nr_free(hookpath);
614-
615608
/*
616609
* Purpose: Instrument Drupal Attribute Hooks for Drupal 11.1+
617610
*
@@ -631,10 +624,6 @@ static bool nr_drupal_hook_attribute_instrument(zval* module_handler) {
631624
zval* module_val = NULL;
632625
zend_ulong key_num = 0;
633626

634-
char* hook_str = NULL;
635-
char* class_str = NULL;
636-
char* method_str = NULL;
637-
char* module_str = NULL;
638627
char* hookpath = NULL;
639628

640629
hook_implementation_map = nr_php_get_zval_object_property(
@@ -648,7 +637,7 @@ static bool nr_drupal_hook_attribute_instrument(zval* module_handler) {
648637
nrl_warning(NRL_FRAMEWORK,
649638
"hookImplementationsMap[hook = %s]: invalid value",
650639
NRSAFESTR(ZEND_STRING_VALUE(hook_key)));
651-
NR_FREE_HOOK_MEM
640+
nr_free(hookpath);
652641
return false;
653642
}
654643

@@ -660,41 +649,38 @@ static bool nr_drupal_hook_attribute_instrument(zval* module_handler) {
660649
nrl_warning(NRL_FRAMEWORK,
661650
"hookImplementationsMap[class = %s]: invalid value",
662651
NRSAFESTR(ZEND_STRING_VALUE(class_key)));
663-
NR_FREE_HOOK_MEM
652+
nr_free(hookpath);
664653
return false;
665654
}
666655

667656
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(class_val), key_num, method_key,
668657
module_val) {
669658
(void)key_num;
670659

671-
NR_FREE_HOOK_MEM
672-
673660
if ((NULL == method_key)
674661
|| (0 == nr_php_is_zval_valid_string(module_val))) {
675662
nrl_warning(NRL_FRAMEWORK,
676663
"hookImplementationsMap[method = %s]: invalid value",
677664
NRSAFESTR(ZEND_STRING_VALUE(method_key)));
678-
NR_FREE_HOOK_MEM
665+
nr_free(hookpath);
679666
return false;
680667
}
681668

682-
hook_str = nr_strdup(ZEND_STRING_VALUE(hook_key));
683-
class_str = nr_strdup(ZEND_STRING_VALUE(class_key));
684-
method_str = nr_strdup(ZEND_STRING_VALUE(method_key));
685-
module_str = nr_strdup(Z_STRVAL_P(module_val));
686-
687669
if (0
688670
== nr_stricmp(ZEND_STRING_VALUE(class_key),
689671
"Drupal\\Core\\Extension\\ProceduralCall")) {
690-
hookpath = nr_formatf("%s", method_str);
672+
hookpath = nr_formatf("%s", ZEND_STRING_VALUE(method_key));
691673
} else {
692-
hookpath = nr_formatf("%s::%s", class_str, method_str);
674+
hookpath = nr_formatf("%s::%s", ZEND_STRING_VALUE(class_key),
675+
ZEND_STRING_VALUE(method_key));
693676
}
694677

695-
nr_php_wrap_user_function_drupal(hookpath, nr_strlen(hookpath),
696-
module_str, nr_strlen(module_str),
697-
hook_str, nr_strlen(hook_str));
678+
nr_php_wrap_user_function_drupal(
679+
hookpath, nr_strlen(hookpath), Z_STRVAL_P(module_val),
680+
Z_STRLEN_P(module_val), ZEND_STRING_VALUE(hook_key),
681+
ZEND_STRING_LEN(hook_key));
682+
683+
nr_free(hookpath);
698684
}
699685
ZEND_HASH_FOREACH_END();
700686
}
@@ -705,16 +691,13 @@ static bool nr_drupal_hook_attribute_instrument(zval* module_handler) {
705691
} else {
706692
nrl_warning(NRL_FRAMEWORK,
707693
"hookImplementationsMap property not a valid array");
708-
NR_FREE_HOOK_MEM
709694
return false;
710695
}
711696
} else {
712697
nrl_warning(NRL_FRAMEWORK, "NULL hookImplementationsMap object property");
713-
NR_FREE_HOOK_MEM
714698
return false;
715699
}
716700

717-
NR_FREE_HOOK_MEM
718701
return true;
719702
}
720703

0 commit comments

Comments
 (0)