Skip to content

Cython makes little use of PySet APIs #2042

@pitrou

Description

@pitrou

If I cythonize the following code:

# cython: language_level=3

cpdef use_dict(dict d, u, v, w):
    if u in d:
        del d[u]
    d.pop(v, None)
    d[w] = 1
    return [x for x in d if x]

cpdef use_set(set s, u, v, w):
    if u in s:
        s.remove(u)
    s.discard(v)
    s.add(w)
    return [x for x in s if x]

Then most of use_dict exploits the PyDictconcrete APIs (except for the .pop call which goes through a Python method call), but use_set exploits none of the PySet concrete API except for PySet_Add.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions