Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding memmem() to QB64PE
#13
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):

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."
Reply


Messages In This Thread
Adding memmem() to QB64PE - by Sanmayce - 03-06-2025, 07:44 AM
RE: Adding memmem() to QB64PE - by grymmjack - 03-06-2025, 08:13 PM
RE: Adding memmem() to QB64PE - by madscijr - 03-07-2025, 03:22 PM
RE: Adding memmem() to QB64PE - by Petr - 03-07-2025, 05:03 PM
RE: Adding memmem() to QB64PE - by madscijr - 03-07-2025, 05:58 PM
RE: Adding memmem() to QB64PE - by SMcNeill - 03-07-2025, 05:03 PM
RE: Adding memmem() to QB64PE - by RhoSigma - 03-07-2025, 06:57 PM
RE: Adding memmem() to QB64PE - by Sanmayce - 03-08-2025, 08:56 PM
RE: Adding memmem() to QB64PE - by SMcNeill - 03-07-2025, 07:47 PM
RE: Adding memmem() to QB64PE - by Petr - 03-07-2025, 07:53 PM
RE: Adding memmem() to QB64PE - by Petr - 03-08-2025, 10:53 PM
RE: Adding memmem() to QB64PE - by SMcNeill - 03-08-2025, 11:17 PM
RE: Adding memmem() to QB64PE - by Sanmayce - 03-08-2025, 11:38 PM
RE: Adding memmem() to QB64PE - by Sanmayce - 03-08-2025, 11:33 PM
RE: Adding memmem() to QB64PE - by SMcNeill - 03-08-2025, 11:38 PM
RE: Adding memmem() to QB64PE - by Petr - 03-08-2025, 11:46 PM
RE: Adding memmem() to QB64PE - by Sanmayce - Yesterday, 02:00 AM
RE: Adding memmem() to QB64PE - by Sanmayce - Yesterday, 02:08 AM



Users browsing this thread: 15 Guest(s)