From: Luke Kenneth Casson Leighton Date: Wed, 29 Sep 2021 12:32:39 +0000 (+0100) Subject: minor cleanup of __Cat__ and Cat to more compact code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=bc9d31ff811069fc58fff3f6d12c833debc921ea;p=nmigen.git minor cleanup of __Cat__ and Cat to more compact code --- diff --git a/nmigen/hdl/ast.py b/nmigen/hdl/ast.py index 2f0625f..e47c833 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) @@ -849,12 +848,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)