From 4e114b2a909ff66658e7c9db7ad10f59c7cc30fb Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Wed, 29 Sep 2021 13:32:39 +0100 Subject: [PATCH] minor cleanup of __Cat__ and Cat to more compact code --- nmigen/hdl/ast.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/nmigen/hdl/ast.py b/nmigen/hdl/ast.py index abd27b3..0a4d75b 100644 --- a/nmigen/hdl/ast.py +++ b/nmigen/hdl/ast.py @@ -155,8 +155,7 @@ class Value(metaclass=ABCMeta): return _InternalRepl(self, count, src_loc_at=src_loc_at) def __Cat__(self, *args, src_loc_at=0): - args = [self] + list(args) - return _InternalCat(*args, src_loc_at=src_loc_at) + return _InternalCat(self, *args, src_loc_at=src_loc_at) def __Mux__(self, val1, val0): return _InternalMux(self, val1, val0) @@ -846,12 +845,11 @@ def Cat(*args, src_loc_at=0): if len(args) == 0: return _InternalCat(*args, src_loc_at=src_loc_at) # determine if the first is a UserValue. - if isinstance(args[0], UserValue): - first = args[0] # take UserValue directly, do not downcast - else: - first = Value.cast(args[0]) # ok to downcast to Value + first, rest = args[0], args[1:] + if not isinstance(args[0], UserValue): + first = Value.cast(first) # ok to downcast to Value # all other arguments are safe to downcast to Value - rest = [Value.cast(v) for v in flatten(args[1:])] + rest = map(Value.cast, rest) # assume first item defines the "handling" for all others return first.__Cat__(*rest, src_loc_at=src_loc_at) -- 2.30.2