-
Notifications
You must be signed in to change notification settings - Fork 242
Open
Labels
untidinessNot exactly a bug, but could do betterNot exactly a bug, but could do better
Milestone
Description
At the moment, there's a pre-compilation pass of chars into METAs.
Then, there are two passes over the METAs, once to find the length of the buffer, then secondly to write into the allocated buffer.
Can we just combine those? We'd need to have a buffer allocation strategy:
- Some heuristics for initial size (which could be guessed reasonably accurately from the META pass)
- Then if we need more buffer space, we can realloc to 1.5× (for example). A bit like appending to a dynamic container: resize with geometric growth
- Finally, if there's any wastage at the end (eg. we ended up allocating 350 bytes but only used 300) then we could realloc down to release the unused space. Or, just accept it as OK, if the overestimate was small.
The upside would be: simpler code! And faster for most users (since only one pass needed). This is assuming that the change from 1×malloc + two pass compilation → 1×malloc + 1×realloc + single pass is actually an improvement.
The downside would be marginally higher memory usage for users with many many regexes, but realloc'ing down to the correct size at the end should solve that.
Getting rid of all the lengthptr != NULL code would be really quite nice.
Metadata
Metadata
Assignees
Labels
untidinessNot exactly a bug, but could do betterNot exactly a bug, but could do better