03-08-2025, 11:33 PM
Let's see what the current pseudo-memmem i.e. instr offers, the code below is taken from the QB64PE repository (from the releases section):
An epitomy of basic functionality and the 2GB limitation due to int32_t start (in fact due to using str(ings) instead of mem(ory)).
Not a modern function, no doubt.
The modern and open QB64 should have 64bit functions in its arsenal.
Just tried on my fastest laptop instr vs (Railgun from the GitHub repository):
On the screenshot I see 4x speed up, speed is religion, but sharing such a gem seems a mistake, it looks bad (especially when a "maintainer" calling me a spammer and bot) for QB64 community , shame on you @SMcNeill
Code: (Select All)
int32_t func_instr(int32_t start, qbs *str, qbs *substr, int32_t passed) {
// QB64 difference: start can be 0 or negative
// justification-start could be larger than the length of string to search in QBASIC
static uint8_t *limit, *base;
static uint8_t firstc;
if (!passed)
start = 1;
if (!str->len)
return 0;
if (start < 1) {
start = 1;
if (!substr->len)
return 0;
}
if (start > str->len)
return 0;
if (!substr->len)
return start;
if ((start + substr->len - 1) > str->len)
return 0;
limit = str->chr + str->len;
firstc = substr->chr[0];
base = str->chr + start - 1;
nextchar:
base = (uint8_t *)memchr(base, firstc, limit - base);
if (!base)
return 0;
if ((base + substr->len) > limit)
return 0;
if (!memcmp(base, substr->chr, substr->len))
return base - str->chr + 1;
base++;
if ((base + substr->len) > limit)
return 0;
goto nextchar;
}
An epitomy of basic functionality and the 2GB limitation due to int32_t start (in fact due to using str(ings) instead of mem(ory)).
Not a modern function, no doubt.
The modern and open QB64 should have 64bit functions in its arsenal.
Just tried on my fastest laptop instr vs (Railgun from the GitHub repository):
On the screenshot I see 4x speed up, speed is religion, but sharing such a gem seems a mistake, it looks bad (especially when a "maintainer" calling me a spammer and bot) for QB64 community , shame on you @SMcNeill
"He learns not to learn and reverts to what the masses pass by."