hpy
hpy copied to clipboard
Request for Comments: Added UnicodeBuilder
RfC
This is a very early draft for an implementation of UnicodeBuilder. As @antocuni pointed out in https://github.com/cklein/hpy/pull/1, a having a discussion around the API first is a good idea, so take the implementation details with a grain of salt and have a focus on the API. Maybe it's easier to have a discussion on #181 first.
The first iteration (first commit) was very close to ListBuilder and TupleBuilder although it seemed to make sense to preallocate memory.
This changed in the second iteration and it turned out to be a lot like HPyTracker, so it took over some naming conventions. One of the main differenes is that it uses a C-Python list under the hood to store objects.
Currently there's no way to add objects beyond the initial capacity. If this is continuing to use a C-Python list, the implementation could switch back from PyList_SET_ITEM to PyList_Append which automatically handles reallocation including overallocation. Or the storage could be setup similar to HPy_Tracker and share the reallocation strategy. A third option would be to internally use a HPy_Tracker, it already provides everything that's needed.