-
-
Couldn't load subscription status.
- Fork 33.2k
gh-130167: Improve speed of _pydecimal._all_zeros and _pydecimal._exact_half by replacing re
#132065
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-130167: Improve speed of _pydecimal._all_zeros and _pydecimal._exact_half by replacing re
#132065
Changes from 6 commits
1bd422a
d5e634c
7037f19
1b34a89
c498ae6
328c99b
b6a8014
027d93d
34486dd
faae133
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6076,8 +6076,13 @@ def _convert_for_comparison(self, other, equality_op=False): | |
| \Z | ||
| """, re.VERBOSE | re.IGNORECASE).match | ||
|
|
||
| _all_zeros = re.compile('0*$').match | ||
| _exact_half = re.compile('50*$').match | ||
| # Checks for regex 0*$ | ||
| def _all_zeros(d_int,prec=0): | ||
|
||
| return '0' in d_int and d_int.endswith((len(d_int) - prec) * '0') | ||
|
|
||
| # Checks for regex 50*$ | ||
| def _exact_half(d_int, prec=0): | ||
| return len(d_int) >= prec + 1 and d_int[prec] == '5' and d_int.endswith(max(len(d_int) - prec - 1, 0) * '0') | ||
Marius-Juston marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ##### PEP3101 support functions ############################################## | ||
| # The functions in this section have little to do with the Decimal | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Improved performance of :func:`_pydecimal._all_zeros` by an average of | ||
| ~1.7x and :func:`_pydecimal._exact_half` by ~1.38x. Patch by Marius Juston |
Uh oh!
There was an error while loading. Please reload this page.