Unify `PyUncode_Count` and `unicode_count` · Issue #97982 · python/cpython · GitHub
Skip to content

Unify PyUncode_Count and unicode_count #97982

@sobolevn

Description

@sobolevn

Feature or enhancement

Right now PyUnicode_Count from

and unicode_count from

cpython/Objects/unicodeobject.c

Lines 10854 to 10916 in cbdeda8

share a lot of code.

They can be unified, because the do the same thing.

Pitch

Citing @encukou:

Apparently unicode_count missed an optimization in 2011, otherwise they're equivalent (except arg parsing & converting the return value). Merging them could add the optimization to unicode_count.
If you want to work on that, note that there's also anylib_count that duplicates the main switch.

Previous discussion

Link: #96929

PR in the works.

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions