Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce BytesBuilder #181

Open
antocuni opened this issue Mar 4, 2021 · 5 comments
Open

Introduce BytesBuilder #181

antocuni opened this issue Mar 4, 2021 · 5 comments

Comments

@antocuni
Copy link
Collaborator

antocuni commented Mar 4, 2021

#127 and #179 made it official that we can't create "half-ready" strings which are supposed to be filled after creation.

However, there are cases in which this is a legitimate use case and currently it is not supported by HPy. We should:

  1. introduce StringBuilder, similar to the existing TupleBuilder and ListBuilder
  2. modify the error message raised by HPyBytes_FromStringAndSize to point the user to the right solution. Something like ... please use StringBuilder instead.
@cklein
Copy link
Contributor

cklein commented Apr 11, 2021

I started writing some different implementations for a PoC (https://github.com/cklein/hpy/tree/cklein-stringbuilder), but maybe the people who started the project or have been contributing for a longer time have a clearer vision of how the API should look like.

What would be the basic operations?
Would you expect the operands to be HPyUnicode objects or c strings?

@TeamSpen210
Copy link

Would it be worth it to add a 2-stage accumulator, like _PyAccu? That's used for StringIO and the json module, it periodically takes the small strings accumulated and compacts them into single large strings. That way building a large string it doesn't have too much overhead.

@hodgestar
Copy link
Contributor

@TeamSpen210 That sounds like a cool optimization to have under the hood, although I wouldn't make it part of the API (not that you or CPython seemed to be suggesting that).

@antocuni
Copy link
Collaborator Author

note: the actual API to use for this is being discussed in #214

@antocuni antocuni changed the title Introduce StringBuilder Introduce BytesBuilder Jun 11, 2021
@Albert55554
Copy link

Need to discuss cpython

@timfel timfel added this to the Version 0.9 milestone Nov 1, 2022
@fangerer fangerer modified the milestones: ABI version 1, ABI version 2 Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants