# HG changeset patch # User Paul Boddie # Date 1530626522 -7200 # Node ID 8e119abbd91c310b0697e53ddc84600af4577cb9 # Parent 0cac8b718fdc44ddb75b42187fcc9f95e9da5ed1 Introduced a class (unpackable) and method (__get_single_item_unchecked__) to support sequence unpacking without index checking overhead, since the translator emits a test for the length of each sequence and controls the actual index values used. diff -r 0cac8b718fdc -r 8e119abbd91c common.py --- a/common.py Tue Jul 03 15:58:44 2018 +0200 +++ b/common.py Tue Jul 03 16:02:02 2018 +0200 @@ -462,7 +462,7 @@ for i, node in enumerate(n.nodes): statements.append( compiler.ast.Assign([node], compiler.ast.CallFunc( - compiler.ast.Getattr(compiler.ast.Name(temp), "__get_single_item__"), + compiler.ast.Getattr(compiler.ast.Name(temp), "__get_single_item_unchecked__"), [compiler.ast.Const(i, str(i))])) ) diff -r 0cac8b718fdc -r 8e119abbd91c lib/__builtins__/list.py --- a/lib/__builtins__/list.py Tue Jul 03 15:58:44 2018 +0200 +++ b/lib/__builtins__/list.py Tue Jul 03 16:02:02 2018 +0200 @@ -3,7 +3,7 @@ """ List objects. -Copyright (C) 2015, 2016, 2017 Paul Boddie +Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -20,11 +20,11 @@ """ from __builtins__.iteration.iterator import itemiterator -from __builtins__.sequence import sequence, _get_absolute_index +from __builtins__.sequence import unpackable, _get_absolute_index from native import list_append, list_concat, list_element, list_init, \ list_len, list_nonempty, list_setelement, list_setsize -class list(sequence): +class list(unpackable): "Implementation of list." diff -r 0cac8b718fdc -r 8e119abbd91c lib/__builtins__/sequence.py --- a/lib/__builtins__/sequence.py Tue Jul 03 15:58:44 2018 +0200 +++ b/lib/__builtins__/sequence.py Tue Jul 03 16:02:02 2018 +0200 @@ -20,7 +20,7 @@ """ from __builtins__.int import maxint -from native import isinstance as _isinstance, is_int +from native import isinstance as _isinstance, is_int, list_element class itemaccess: @@ -255,6 +255,19 @@ # __iter__(self) +class unpackable(sequence): + + "Class for list and tuple unpacking." + + def __get_single_item_unchecked__(self, index): + + """ + NOTE: Should restrict this to internal translator use. + NOTE: This also uses implementation-specific access. + """ + + return list_element(self.__data__, index) + def _get_absolute_index(index, length): """ diff -r 0cac8b718fdc -r 8e119abbd91c lib/__builtins__/tuple.py --- a/lib/__builtins__/tuple.py Tue Jul 03 15:58:44 2018 +0200 +++ b/lib/__builtins__/tuple.py Tue Jul 03 16:02:02 2018 +0200 @@ -3,7 +3,7 @@ """ Tuple objects. -Copyright (C) 2015, 2016, 2017 Paul Boddie +Copyright (C) 2015, 2016, 2017, 2018 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -20,11 +20,11 @@ """ from __builtins__.iteration.iterator import itemiterator -from __builtins__.sequence import hashable, sequence +from __builtins__.sequence import hashable, unpackable from native import tuple_init, \ list_element, list_len, list_setsize, list_setelement -class tuple(sequence, hashable): +class tuple(unpackable, hashable): "Implementation of tuple." @@ -65,7 +65,7 @@ 'step'. """ - return tuple(get_using(sequence.__getslice__, self)(start, end, step)) + return tuple(get_using(unpackable.__getslice__, self)(start, end, step)) def __len__(self):