1
1
Fork 0
mirror of https://github.com/pbatard/rufus.git synced 2024-08-14 23:57:05 +00:00

[perf] Cache constant lengths instead of reevaluating

This commit is contained in:
Tsarevich Dmitry 2020-02-23 20:02:00 +03:00
parent 2253543a5c
commit 09cb8aceba
No known key found for this signature in database
GPG key ID: E3C61298FF5B1274

View file

@ -960,7 +960,7 @@ char* insert_section_data(const char* filename, const char* section, const char*
wchar_t *wsection = NULL, *wfilename = NULL, *wtmpname = NULL, *wdata = NULL, bom = 0; wchar_t *wsection = NULL, *wfilename = NULL, *wtmpname = NULL, *wdata = NULL, bom = 0;
wchar_t buf[1024]; wchar_t buf[1024];
FILE *fd_in = NULL, *fd_out = NULL; FILE *fd_in = NULL, *fd_out = NULL;
size_t i, size; size_t i, size, wsection_len;
int mode = 0; int mode = 0;
char *ret = NULL, tmp[2]; char *ret = NULL, tmp[2];
@ -979,6 +979,7 @@ char* insert_section_data(const char* filename, const char* section, const char*
uprintf(conversion_error, section); uprintf(conversion_error, section);
goto out; goto out;
} }
wsection_len = wcslen(wsection);
wdata = utf8_to_wchar(data); wdata = utf8_to_wchar(data);
if (wdata == NULL) { if (wdata == NULL) {
uprintf(conversion_error, data); uprintf(conversion_error, data);
@ -1033,7 +1034,7 @@ char* insert_section_data(const char* filename, const char* section, const char*
i += wcsspn(&buf[i], wspace); i += wcsspn(&buf[i], wspace);
// Our token should begin a line // Our token should begin a line
if (_wcsnicmp(&buf[i], wsection, wcslen(wsection)) != 0) { if (_wcsnicmp(&buf[i], wsection, wsection_len) != 0) {
fputws(buf, fd_out); fputws(buf, fd_out);
continue; continue;
} }
@ -1094,7 +1095,7 @@ char* replace_in_token_data(const char* filename, const char* token, const char*
wchar_t *wtoken = NULL, *wfilename = NULL, *wtmpname = NULL, *wsrc = NULL, *wrep = NULL, bom = 0; wchar_t *wtoken = NULL, *wfilename = NULL, *wtmpname = NULL, *wsrc = NULL, *wrep = NULL, bom = 0;
wchar_t buf[1024], *torep; wchar_t buf[1024], *torep;
FILE *fd_in = NULL, *fd_out = NULL; FILE *fd_in = NULL, *fd_out = NULL;
size_t i, ns, size; size_t i, ns, size, wtoken_len, wsrc_len;
int mode = 0; int mode = 0;
char *ret = NULL, tmp[2]; char *ret = NULL, tmp[2];
@ -1115,11 +1116,13 @@ char* replace_in_token_data(const char* filename, const char* token, const char*
uprintf(conversion_error, token); uprintf(conversion_error, token);
goto out; goto out;
} }
wtoken_len = wcslen(wtoken);
wsrc = utf8_to_wchar(src); wsrc = utf8_to_wchar(src);
if (wsrc == NULL) { if (wsrc == NULL) {
uprintf(conversion_error, src); uprintf(conversion_error, src);
goto out; goto out;
} }
wsrc_len = wcslen(wsrc);
wrep = utf8_to_wchar(rep); wrep = utf8_to_wchar(rep);
if (wrep == NULL) { if (wrep == NULL) {
uprintf(conversion_error, rep); uprintf(conversion_error, rep);
@ -1176,13 +1179,13 @@ char* replace_in_token_data(const char* filename, const char* token, const char*
i += wcsspn(&buf[i], wspace); i += wcsspn(&buf[i], wspace);
// Our token should begin a line // Our token should begin a line
if (_wcsnicmp(&buf[i], wtoken, wcslen(wtoken)) != 0) { if (_wcsnicmp(&buf[i], wtoken, wtoken_len) != 0) {
fputws(buf, fd_out); fputws(buf, fd_out);
continue; continue;
} }
// Token was found, move past token // Token was found, move past token
i += wcslen(wtoken); i += wtoken_len;
// Skip whitespaces after token (while making sure there's at least one) // Skip whitespaces after token (while making sure there's at least one)
ns = wcsspn(&buf[i], wspace); ns = wcsspn(&buf[i], wspace);
@ -1196,7 +1199,7 @@ char* replace_in_token_data(const char* filename, const char* token, const char*
continue; continue;
} }
i = (torep-buf) + wcslen(wsrc); i = (torep-buf) + wsrc_len;
*torep = 0; *torep = 0;
// coverity[invalid_type] // coverity[invalid_type]
fwprintf_s(fd_out, L"%s%s%s", buf, wrep, &buf[i]); fwprintf_s(fd_out, L"%s%s%s", buf, wrep, &buf[i]);