Speed-up named tuple's _make() constructor.

This commit is contained in:
Raymond Hettinger 2008-01-06 22:11:54 +00:00
parent 35f8861386
commit 844f71b7e4
1 changed files with 2 additions and 2 deletions

View File

@ -65,9 +65,9 @@ def namedtuple(typename, field_names, verbose=False):
def __new__(cls, %(argtxt)s):
return tuple.__new__(cls, (%(argtxt)s)) \n
@classmethod
def _make(cls, iterable):
def _make(cls, iterable, new=tuple.__new__, len=len):
'Make a new %(typename)s object from a sequence or iterable'
result = tuple.__new__(cls, iterable)
result = new(cls, iterable)
if len(result) != %(numfields)d:
raise TypeError('Expected %(numfields)d arguments, got %%d' %% len(result))
return result \n