lib: Move 'strlen' function outside of the loop

From PVS Studio:
V814
Decreased performance. The 'strlen' function was called multiple times inside the body of a loop.
https://www.viva64.com/en/w/V814/print

Signed-off-by: Vitalii Koshura <lestat.de.lionkur@gmail.com>
This commit is contained in:
Vitalii Koshura 2017-05-01 02:41:15 +03:00
parent ac291dd0d1
commit 3d2fdc8508
No known key found for this signature in database
GPG Key ID: CE0DB1726070A5A3
2 changed files with 4 additions and 2 deletions

View File

@ -1552,6 +1552,7 @@ UINT WINAPI diagnostics_unhandled_exception_monitor(LPVOID /* lpParameter */) {
CONTEXT c;
BOINC_WINDOWCAPTURE window_info;
BOINC_THREADLISTENTRY *pThreadEntry = NULL;
const size_t boinc_install_dir_len = strlen(diagnostics_get_boinc_install_dir());
// We should not suspend our crash dump thread.
diagnostics_set_thread_exempt_suspend();
@ -1614,7 +1615,7 @@ UINT WINAPI diagnostics_unhandled_exception_monitor(LPVOID /* lpParameter */) {
// Kickstart the debugger extensions, look for the debugger files
// in the install directory if it is defined, otherwise look
// in the data directory.
if (0 != strlen(diagnostics_get_boinc_install_dir())) {
if (0 != boinc_install_dir_len) {
bDebuggerInitialized = !DebuggerInitialize(
diagnostics_get_boinc_install_dir(),
diagnostics_get_symstore(),

View File

@ -321,6 +321,7 @@ void extract_venue(const char* in, const char* venue_name, char* out, int len) {
const char* p, *q;
char* wp;
char buf[256];
const size_t venue_close_tag_len = strlen("</venue>");
snprintf(buf, sizeof(buf), "<venue name=\"%s\">", venue_name);
p = strstr(in, buf);
if (p) {
@ -344,7 +345,7 @@ void extract_venue(const char* in, const char* venue_name, char* out, int len) {
strncat(out, q, p-q);
q = strstr(p, "</venue>");
if (!q) break;
q += strlen("</venue>");
q += venue_close_tag_len;
}
}
}