← Back to context

Comment by kevingadd

4 years ago

You can keep the existing sscanf function and now strlen is O(1) so the bug is gone. Any questions?

I just can’t figure out the exact code.

  • I think your code would be pretty much the same, sscanf, strlen and all. The main differences would be the standard library's implementations of strlen and whatever function you use to read the file into a string in the first place.

    •   str_t json = loadfile();
        size_t offset = random();
        sscanf(“%d”, ?);
      

      With opaque str_t you can’t just json[offset]. Should sscanf take offset with every string (sscanf(fmt, s, off))? Should we copy a slice of json and parse it? Should str_t have zerocopy mirroring ability (s2 = strmirror(s, off, len))? How many of these three are just a snakeoil that changes nothing?

      It’s only pretty much the same until you try to write actual code with a new idea in mind.

      7 replies →