Issue #19232: Speed up decimal import. Additionally, since _decimal is

self-contained, this change facilitates maintenance and the Python version
can be easily imported for experimentation.
This commit is contained in:
Stefan Krah 2014-09-10 17:58:15 +02:00
parent 082a9b1274
commit b578f8a1ef
4 changed files with 6404 additions and 6406 deletions

6389
Lib/_pydecimal.py Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -4173,9 +4173,7 @@ class CheckAttributes(unittest.TestCase):
self.assertEqual(C.__version__, P.__version__) self.assertEqual(C.__version__, P.__version__)
self.assertEqual(C.__libmpdec_version__, P.__libmpdec_version__) self.assertEqual(C.__libmpdec_version__, P.__libmpdec_version__)
x = dir(C) self.assertEqual(dir(C), dir(P))
y = [s for s in dir(P) if '__' in s or not s.startswith('_')]
self.assertEqual(set(x) - set(y), set())
def test_context_attributes(self): def test_context_attributes(self):

View File

@ -36,6 +36,7 @@ from test.support import import_fresh_module
from randdec import randfloat, all_unary, all_binary, all_ternary from randdec import randfloat, all_unary, all_binary, all_ternary
from randdec import unary_optarg, binary_optarg, ternary_optarg from randdec import unary_optarg, binary_optarg, ternary_optarg
from formathelper import rand_format, rand_locale from formathelper import rand_format, rand_locale
from _pydecimal import _dec_from_triple
C = import_fresh_module('decimal', fresh=['_decimal']) C = import_fresh_module('decimal', fresh=['_decimal'])
P = import_fresh_module('decimal', blocked=['_decimal']) P = import_fresh_module('decimal', blocked=['_decimal'])
@ -370,7 +371,7 @@ class SkipHandler:
return abs(a - b) return abs(a - b)
def standard_ulp(self, dec, prec): def standard_ulp(self, dec, prec):
return P._dec_from_triple(0, '1', dec._exp+len(dec._int)-prec) return _dec_from_triple(0, '1', dec._exp+len(dec._int)-prec)
def rounding_direction(self, x, mode): def rounding_direction(self, x, mode):
"""Determine the effective direction of the rounding when """Determine the effective direction of the rounding when
@ -401,10 +402,10 @@ class SkipHandler:
# Convert infinities to the largest representable number + 1. # Convert infinities to the largest representable number + 1.
x = exact x = exact
if exact.is_infinite(): if exact.is_infinite():
x = P._dec_from_triple(exact._sign, '10', context.p.Emax) x = _dec_from_triple(exact._sign, '10', context.p.Emax)
y = rounded y = rounded
if rounded.is_infinite(): if rounded.is_infinite():
y = P._dec_from_triple(rounded._sign, '10', context.p.Emax) y = _dec_from_triple(rounded._sign, '10', context.p.Emax)
# err = (rounded - exact) / ulp(rounded) # err = (rounded - exact) / ulp(rounded)
self.maxctx.prec = p * 2 self.maxctx.prec = p * 2