Skip to content

Commit

Permalink
reduce # of calls to string_to_lower
Browse files Browse the repository at this point in the history
  • Loading branch information
lavarou committed Jan 15, 2025
1 parent 860d9a5 commit 346e4d5
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions agent/php_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,16 +1044,14 @@ static void nr_execute_handle_library(const char* filename,
}
}
#else
char* filename_lc = nr_string_to_lowercase(filename);
nr_library_table_t* library = (nr_library_table_t *) nr_suffix_lookup_hashmap_get(&library_lookup, filename_lc, filename_len);
nr_library_table_t* library = (nr_library_table_t *) nr_suffix_lookup_hashmap_get(&library_lookup, filename, filename_len);
if (library) {
nrl_debug(NRL_INSTRUMENT, "detected library=%s", library->library_name);
nr_fw_support_add_library_supportability_metric(NRPRG(txn), library->library_name);
if (NULL != library->enable) {
library->enable(TSRMLS_C);
}
}
nr_free(filename_lc);
#endif
}

Expand Down Expand Up @@ -1116,8 +1114,7 @@ static void nr_execute_handle_logging_framework(const char* filename,
}
}
#else
char* filename_lc = nr_string_to_lowercase(filename);
nr_library_table_t* library = (nr_library_table_t *) nr_suffix_lookup_hashmap_get(&logging_library_lookup, filename_lc, filename_len);
nr_library_table_t* library = (nr_library_table_t *) nr_suffix_lookup_hashmap_get(&logging_library_lookup, filename, filename_len);
if (library) {
nrl_debug(NRL_INSTRUMENT, "detected library=%s",
library->library_name);
Expand All @@ -1132,7 +1129,6 @@ static void nr_execute_handle_logging_framework(const char* filename,
nr_fw_support_add_logging_supportability_metric(
NRPRG(txn), library->library_name, is_enabled);
}
nr_free(filename_lc);
#endif
}

Expand All @@ -1150,14 +1146,12 @@ static void nr_execute_handle_package(const char* filename,
}
}
#else
char* filename_lc = nr_string_to_lowercase(filename);
nr_vuln_mgmt_table_t* vuln_mgmt_package = (nr_vuln_mgmt_table_t *) nr_suffix_lookup_hashmap_get(&vuln_mgmt_package_lookup, filename_lc, filename_len);
nr_vuln_mgmt_table_t* vuln_mgmt_package = (nr_vuln_mgmt_table_t *) nr_suffix_lookup_hashmap_get(&vuln_mgmt_package_lookup, filename, filename_len);
if (vuln_mgmt_package) {
if (NULL != vuln_mgmt_package->enable) {
vuln_mgmt_package->enable(TSRMLS_C);
}
}
nr_free(filename_lc);
#endif
}

Expand All @@ -1174,21 +1168,25 @@ static void nr_execute_handle_package(const char* filename,
static void nr_php_user_instrumentation_from_file(const char* filename,
const size_t filename_len
TSRMLS_DC) {
char* filename_lc = NULL;
/* short circuit if filename_len is 0; a single place short circuit */
if (0 == filename_len) {
nrl_verbosedebug(NRL_AGENT,
"%s - received invalid filename_len for file=%s", __func__,
filename);
return;
}

filename_lc = nr_string_to_lowercase(filename);
nr_execute_handle_framework(all_frameworks, num_all_frameworks, filename,
filename_len TSRMLS_CC);
nr_execute_handle_library(filename, filename_len TSRMLS_CC);
nr_execute_handle_library(filename_lc, filename_len TSRMLS_CC);
nr_execute_handle_autoload(filename, filename_len);
nr_execute_handle_logging_framework(filename, filename_len TSRMLS_CC);
nr_execute_handle_logging_framework(filename_lc, filename_len TSRMLS_CC);
if (NRINI(vulnerability_management_package_detection_enabled)) {
nr_execute_handle_package(filename, filename_len);
nr_execute_handle_package(filename_lc, filename_len);
}
nr_free(filename_lc);
}

/*
Expand Down

0 comments on commit 346e4d5

Please sign in to comment.