Skip to content

Teach strbuf a new trick: STRBUF_INIT_CONST("default") #398

Open
@dscho

Description

@dscho

From https://public-inbox.org/git/[email protected]/:

This new way to initialize an strbuf would set buf to the specified constant string, the appropriate len = strlen(string), and alloc to 0.

That way, we can initialize strbufs with constant values, only allocating memory when/if needed.

We will need to be careful to revisit all strbuf_*() functions to make sure that they test not only for enough space when growing the string, but also when reducing it (unless reducing to len == 0, in which case we can reassign strbuf_slopbuf to the buf field).

We also will need to revisit strbuf_*() to understand alloc < len to mean that we cannot call realloc(), but have to malloc() && memcpy() instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    leftoverbitsFrom the Git mailing list: https://lore.kernel.org/git/?q=%23leftoverbits

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions