mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-17 06:36:13 +03:00
Minor performance improvements setting up intervention's log
- Initialize `log` temporary value on construction instead of doing default initialization and then calling `append`. - Leverage `std::string_view` to replace `const std::string&` parameters in `utils::string::replaceAll` to avoid creating a `std::string` object (and associated allocation and copy) for the string literal`%d`
This commit is contained in:
parent
c947f5e40d
commit
0b5493d4e7
@ -1492,9 +1492,8 @@ bool Transaction::intervention(ModSecurityIntervention *it) {
|
|||||||
it->status = m_it.status;
|
it->status = m_it.status;
|
||||||
|
|
||||||
if (m_it.log != NULL) {
|
if (m_it.log != NULL) {
|
||||||
std::string log("");
|
std::string log(m_it.log);
|
||||||
log.append(m_it.log);
|
utils::string::replaceAll(log, "%d",
|
||||||
utils::string::replaceAll(&log, std::string("%d"),
|
|
||||||
std::to_string(it->status));
|
std::to_string(it->status));
|
||||||
it->log = strdup(log.c_str());
|
it->log = strdup(log.c_str());
|
||||||
} else {
|
} else {
|
||||||
|
@ -254,11 +254,11 @@ unsigned char *c2x(unsigned what, unsigned char *where) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void replaceAll(std::string *str, const std::string& from,
|
void replaceAll(std::string &str, std::string_view from,
|
||||||
const std::string& to) {
|
std::string_view to) {
|
||||||
size_t start_pos = 0;
|
size_t start_pos = 0;
|
||||||
while ((start_pos = str->find(from, start_pos)) != std::string::npos) {
|
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
|
||||||
str->replace(start_pos, from.length(), to);
|
str.replace(start_pos, from.length(), to);
|
||||||
start_pos += to.length();
|
start_pos += to.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ std::vector<std::string> ssplit(std::string str, char delimiter);
|
|||||||
std::pair<std::string, std::string> ssplit_pair(const std::string& str, char delimiter);
|
std::pair<std::string, std::string> ssplit_pair(const std::string& str, char delimiter);
|
||||||
std::vector<std::string> split(std::string str, char delimiter);
|
std::vector<std::string> split(std::string str, char delimiter);
|
||||||
void chomp(std::string *str);
|
void chomp(std::string *str);
|
||||||
void replaceAll(std::string *str, const std::string& from,
|
void replaceAll(std::string &str, std::string_view from,
|
||||||
const std::string& to);
|
std::string_view to);
|
||||||
std::string removeWhiteSpacesIfNeeded(std::string a);
|
std::string removeWhiteSpacesIfNeeded(std::string a);
|
||||||
std::string parserSanitizer(std::string a);
|
std::string parserSanitizer(std::string a);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user