scripts: csv.py: Added explicit z field, reusing -Z/--children
In an effort to move away from magic usage of -i/--enumerate, this adds an explicit z field for differentiating -r/--hot results (and for normal recursive results). Instead of trying to think of a new flag to control this, this just piggybacks on -Z/--children, which now accepts a tuple: - ./scripts/csv.py -z3 -Z - ./scripts/csv.py -z3 -Zchildren - ./scripts/csv.py -z3 -Zz,children The only tricky bit was needing to insert z in front of the by fields, otherwise it was mostly a simplification from the enumerate mess. Another positive side-effect: -r/--hot (and -z/--depth) now implies -Zz,children, removing the annoying/confusing behavior of hotify folding results by default.
This commit is contained in:
+6
-9
@@ -150,6 +150,7 @@ class StructResult(co.namedtuple('StructResult', [
|
||||
_fields = ['off', 'size', 'align']
|
||||
_sort = ['size', 'align']
|
||||
_types = {'off': CsvInt, 'size': CsvInt, 'align': CsvInt}
|
||||
_z = 'z'
|
||||
_children = 'children'
|
||||
|
||||
__slots__ = ()
|
||||
@@ -703,14 +704,14 @@ def fold(Result, results, *,
|
||||
return folded
|
||||
|
||||
def hotify(Result, results, *,
|
||||
enumerates=None,
|
||||
depth=1,
|
||||
hot=None,
|
||||
**_):
|
||||
# note! hotifying risks confusion if you don't enumerate/have a
|
||||
# z field, since it will allow folding across recursive boundaries
|
||||
# note! hotifying risks confusion if you don't have a z field, since
|
||||
# it will allow folding across recursive boundaries
|
||||
|
||||
# hotify only makes sense for recursive results
|
||||
assert hasattr(Result, '_z')
|
||||
assert hasattr(Result, '_children')
|
||||
|
||||
results_ = []
|
||||
@@ -732,12 +733,8 @@ def hotify(Result, results, *,
|
||||
for k_ in ([k] if k else Result._sort)))
|
||||
for k, reverse in it.chain(hot, [(None, False)])))
|
||||
|
||||
hot_.append(r._replace(**(
|
||||
# enumerate?
|
||||
({e: len(hot_) for e in enumerates}
|
||||
if enumerates is not None
|
||||
else {})
|
||||
| {Result._children: []})))
|
||||
# flatten, dropping children
|
||||
hot_.append(r._replace(**{Result._children: []}))
|
||||
|
||||
# recurse?
|
||||
if depth_ > 1:
|
||||
|
||||
Reference in New Issue
Block a user