Skip to content

Add PyDict_NewPresized() function #80

@vstinner

Description

@vstinner

Hi,

The private _PyDict_NewPresized(size) function is used by 11 projects of the PyPI top 15,000 projects. The problem is that it miss the unicode_keys parameter which is a hint to announce if keys are Unicode or not. @methane analyzed how _PyDict_NewPresized(size) is used in various projects and suggests adding a public PyDict_NewPresized(size, unicode_keys) function. See python/cpython#139772 for the discussion.

API: PyObject* PyDict_NewPresized(Py_ssize_t size, int unicode_keys)

  • Return a new empty dictionary with preallocated items, or NULL on failure.
  • size is a hint to preallocate items.
  • If unicode_keys is non-zero, optimize lookup for Unicode keys.

Pull request.

Since unicode_keys is an implementation detail, I hesitate to put the function in the PyUnstable category: PyUnstable_Dict_NewPresized(). What do you think?

Vote:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions