Skip to content

gh-160501: Cover the UCS4 adaptive search path in test_str - #160502

Open
wlkr73 wants to merge 1 commit into
python:mainfrom
wlkr73:gh-160501-adaptive-ucs4
Open

wlkr73 wants to merge 1 commit into
python:mainfrom
wlkr73:gh-160501-adaptive-ucs4

Conversation

@wlkr73

@wlkr73 wlkr73 commented Oct 23, 2026 •

Copy link
Copy Markdown

Adds a test beside test_find in Lib/test/test_str.py that drives the
adaptive search path with non-BMP characters.

Objects/stringlib/fastsearch.h compiles adaptive_find once per character
width, and only the ASCII and UCS1 copies ran under the whole suite:

Function 'ucs4lib_adaptive_find'   Lines executed:0.00% of 39
Function 'ucs2lib_adaptive_find'   Lines executed:66.67% of 39
Function 'ucs1lib_adaptive_find'   Lines executed:71.79% of 39
Function 'asciilib_adaptive_find'  Lines executed:79.49% of 39

The adaptive branch needs a haystack of at least 2500 characters, a needle of at
least 100, and a needle at least a third of the haystack. test_adaptive_find
meets all three with 'a' and 'b', so the UCS4 instantiation stayed cold.

The new test repeats that shape with '\U0001d11e' and '\U0001d11f', checking
both a miss and a hit, through find and count. With it,
ucs4lib_adaptive_find goes from 0.00% to 89.74% of 39 lines; the branches left
are the count and reverse-search modes, which are separate entry points and are
covered elsewhere.

Test-only change, no behaviour change, so no NEWS entry.

./python -m test test_str -m "*adaptive*" passes. The new test adds about
0.85 s to test_str on a -O0 --coverage build, which is slower than a normal
one; the whole module runs in roughly 14 s there.

@bedevere-app

bedevere-app Bot commented Oct 23, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@wlkr73

wlkr73 commented Oct 23, 2026

Copy link
Copy Markdown
Author

No NEWS entry needed here: the guide lists "test changes" as exempt in "Changes that require NEWS entries" (devguide, pull-request-lifecycle). This PR only adds a test.

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

Labels

awaiting review skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants