From: Raymond Hettinger Date: Sun, 6 Jan 2008 22:11:54 +0000 (+0000) Subject: Speed-up named tuple's _make() constructor. X-Git-Tag: v2.6a1~707 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=844f71b7e4d8b5cdb61f4800ee14a11f3ee9ad15;p=python Speed-up named tuple's _make() constructor. --- diff --git a/Lib/collections.py b/Lib/collections.py index 39b9229f57..0b86898502 100644 --- a/Lib/collections.py +++ b/Lib/collections.py @@ -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