8000 gh-117431: Adapt str.find and friends to Argument Clinic (#117468) · python/cpython@7ecd55d · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ecd55d

Browse files
gh-117431: Adapt str.find and friends to Argument Clinic (#117468)
This change gives a significant speedup, as the METH_FASTCALL calling convention is now used. The following methods are adapted: - str.count - str.find - str.index - str.rfind - str.rindex
1 parent 345194d commit 7ecd55d

File tree

4 files changed

+439
-217
lines changed

4 files changed

+439
-217
lines changed

Lib/test/string_tests.py

Lines changed: 5 additions & 5 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -1503,15 +1503,15 @@ def test_find_etc_raise_correct_error_messages(self):
15031503
# issue 11828
15041504
s = 'hello'
15051505
x = 'x'
1506-
self.assertRaisesRegex(TypeError, r'^find\(', s.find,
1506+
self.assertRaisesRegex(TypeError, r'^find\b', s.find,
15071507
x, None, None, None)
1508-
self.assertRaisesRegex(TypeError, r'^rfind\(', s.rfind,
1508+
self.assertRaisesRegex(TypeError, r'^rfind\b', s.rfind,
15091509
x, None, None, None)
1510-
self.assertRaisesRegex(TypeError, r'^index\(', s.index,
1510+
self.assertRaisesRegex(TypeError, r'^index\b', s.index,
15111511
x, None, None, None)
1512-
self.assertRaisesRegex(TypeError, r'^rindex\(', s.rindex,
1512+
self.assertRaisesRegex(TypeError, r'^rindex\b', s.rindex,
15131513
x, None, None, None)
1514-
self.assertRaisesRegex(TypeError, r'^count\(', s.count,
1514+
self.assertRaisesRegex(TypeError, r'^count\b', s.count,
15151515
x, None, None, None)
15161516
self.assertRaisesRegex(TypeError, r'^startswith\b', s.startswith,
15171517
x, None, None, None)
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1-
Improve the performance of :meth:`str.startswith` and :meth:`str.endswith`
2-
by adapting them to the :c:macro:`METH_FASTCALL` calling convention.
1+
Improve the performance of the following :class:`str` methods
2+
by adapting them to the :c:macro:`METH_FASTCALL` calling convention:
3+
4+
* :meth:`~str.count`
5+
* :meth:`~str.endswith`
6+
* :meth:`~str.find`
7+
* :meth:`~str.index`
8+
* :meth:`~str.rfind`
9+
* :meth:`~str.rindex`
10+
* :meth:`~str.startswith`

Objects/clinic/unicodeobject.c.h

Lines changed: 280 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0