I am reading through this blog post: https://nee.lv/2021/02/28/How-I-cut-GTA-Online-loading-times-by-70/
I am confused on how:
size_t len = end - str;
If I am correct, strings in C are represented as arrays and C strings have pointers to the first element of that array. So is that above line playing with array subscripts?
They posts these lines:
size_t strlen_cacher(char *str) {
static char *start;
static char *end;
size_t len;
const size_t cap = 20000;
// if we have a "cached" string and current pointer is within it
if (start && str >= start && str <= end) {
// calculate the new strlen
len = end - str;
// if we're near the end, unload self
// we don't want to mess something else up
if (len < cap / 2)
MH_DisableHook((LPVOID)strlen_addr);
// super-fast return!
return len;
}
// count the actual length
// we need at least one measurement of the large JSON
// or normal strlen for other strings
len = builtin_strlen(str);
// if it was the really long string
// save it's start and end addresses
if (len > cap) {
start = str;
end = str + len;
}
// slow, boring return
return len;
}