common: Cache string length in strupper/strlower

Avoids calling strlen every loop iteration.
This commit is contained in:
Lioncash 2015-05-11 03:14:07 -04:00
parent 1059f73fb8
commit a6db883d49

View File

@ -23,15 +23,21 @@ typedef volatile u32 vu32;
typedef volatile u64 vu64; typedef volatile u64 vu64;
inline char* strupper(const char* str) { inline char* strupper(const char* str) {
char* buffer = (char*)malloc(strlen(str) + 1); const size_t string_len = strlen(str);
for (int i = 0; i < strlen(str); ++i) char* buffer = (char*)malloc(string_len + 1);
for (int i = 0; i < string_len; ++i)
buffer[i] = toupper((unsigned)str[i]); buffer[i] = toupper((unsigned)str[i]);
return buffer; return buffer;
} }
inline char* strlower(const char* str) { inline char* strlower(const char* str) {
char* buffer = (char*)malloc(strlen(str) + 1); const size_t string_len = strlen(str);
for (int i = 0; i < strlen(str); ++i) char* buffer = (char*)malloc(string_len + 1);
for (int i = 0; i < string_len; ++i)
buffer[i] = tolower((unsigned)str[i]); buffer[i] = tolower((unsigned)str[i]);
return buffer; return buffer;
} }