Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-55531: Implementnormalize_encoding in C#136643

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
StanFromIreland wants to merge7 commits intopython:main
base:main
Choose a base branch
Loading
fromStanFromIreland:enc-normalize-speedup

Conversation

StanFromIreland
Copy link
Member

@StanFromIrelandStanFromIreland commentedJul 14, 2025
edited by bedevere-appbot
Loading

Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I know that it's a draft but here are already some comments that you can dismiss if you're working on them.

@StanFromIreland
Copy link
MemberAuthor

StanFromIreland commentedJul 14, 2025
edited
Loading

I have cleaned up the changes and ensure the behavior remains the same, however there are still a few points I need input from@malemburg
(And as Benedikt said, should be their own issue)

  • This function is documented as taking strings, but during the 2->3 conversion and undocumented, and untested change was made which allowed it to accept bytes. I have kept it this way (in Python, to make removal simpler), though I think this should either be documented and tested, or removed.
  • The function has been documented asascii only, and forbytes, it is. However, for strings, it has not been enforced with an error. What should we do?

@StanFromIrelandStanFromIreland marked this pull request as ready for reviewJuly 14, 2025 12:54
Copy link
Member

@ZeroIntensityZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Would you mind running some microbenchmarks?

@StanFromIreland
Copy link
MemberAuthor

Benchmarks:

script
import timefrom encodings import normalize_encodingimport pyperfdef bench(loops):    range_it = range(loops)    t0 = time.perf_counter()    for _ in range_it:        normalize_encoding('utf_8')        normalize_encoding('utf\xE9\u20AC\U0010ffff-8')        normalize_encoding('utf   8')        normalize_encoding('%%%~')        normalize_encoding('UTF...8')    return time.perf_counter() - t0runner = pyperf.Runner()runner.bench_time_func('normalize_encoding', bench, inner_loops=30)

Main branch:

normalize_encoding: Mean +- std dev: 173 ns +- 7 ns

This PR:

normalize_encoding: Mean +- std dev: 42.9 ns +- 1.1 ns
ZeroIntensity reacted with thumbs up emojim-aciek reacted with rocket emoji

return NULL;
}

char *normalized = PyMem_Malloc(len + 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It'd be possible to use a VLA for this, but I'm not sure it's worth the additional complexity.@picnixz WDYT?

@malemburg
Copy link
Member

Sorry for the lack of response. I'm currently at EuroPython and pretty busy with other things. I'll have a look on Saturday during the sprints.

StanFromIreland reacted with thumbs up emoji

return NULL;
}

if (PyUnicodeWriter_WriteUTF8(writer, normalized, (Py_ssize_t)strlen(normalized)) < 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The size shouldn't need to be recalculated here. It's alwayslen + 1, right?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

self.assertEqual(normalize('utf\xE9\u20AC\U0010ffff-8'),'utf_8')
self.assertEqual(normalize('utf 8'),'utf_8')

No, it must be done to match the current behavior, where it can change.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@picnixzpicnixzpicnixz left review comments

@ZeroIntensityZeroIntensityZeroIntensity left review comments

@vstinnervstinnerAwaiting requested review from vstinner

@malemburgmalemburgAwaiting requested review from malemburg

@serhiy-storchakaserhiy-storchakaAwaiting requested review from serhiy-storchaka

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@StanFromIreland@malemburg@picnixz@ZeroIntensity

[8]ページ先頭

©2009-2025 Movatter.jp