Skip to content

Commit 43c3ee1

Browse files
committed
Simplify check in tree.mjs
1 parent 0cf643b commit 43c3ee1

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

modules/tree.mjs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ function findBranchComplex(tree, name, lst = undefined, only_search = false) {
362362
if (pos > 0) search = search.slice(0, pos);
363363
}
364364

365-
if (!lst || (lst.arr.length === 0)) return null;
365+
if (!lst?.arr.length)
366+
return null;
366367

367368
for (let n = 0; n < lst.arr.length; ++n) {
368369
let brname = lst.arr[n].fName;
@@ -390,10 +391,9 @@ function findBranchComplex(tree, name, lst = undefined, only_search = false) {
390391
if (brname[pnt - 1] === '.') pnt--;
391392
if (search[pnt] !== '.') continue;
392393

393-
res = findBranchComplex(tree, search, lst.arr[n].fBranches);
394-
if (!res) res = findBranchComplex(tree, search.slice(pnt + 1), lst.arr[n].fBranches);
395-
396-
if (!res) res = { branch: lst.arr[n], rest: search.slice(pnt) };
394+
res = findBranchComplex(tree, search, lst.arr[n].fBranches) ||
395+
findBranchComplex(tree, search.slice(pnt + 1), lst.arr[n].fBranches) ||
396+
{ branch: lst.arr[n], rest: search.slice(pnt) };
397397

398398
break;
399399
}
@@ -1040,8 +1040,7 @@ class TDrawSelector extends TSelector {
10401040
this.leaf = args.leaf;
10411041

10421042
// branch object remains, therefore we need to copy fields to see them all
1043-
this.copy_fields = ((args.branch.fLeaves && (args.branch.fLeaves.arr.length > 1)) ||
1044-
(args.branch.fBranches && (args.branch.fBranches.arr.length > 0))) && !args.leaf;
1043+
this.copy_fields = ((args.branch.fLeaves?.arr.length > 1) || args.branch.fBranches?.arr.length) && !args.leaf;
10451044

10461045
this.addBranch(branch, 'br0', args.direct_branch); // add branch
10471046

@@ -1972,9 +1971,8 @@ async function treeProcess(tree, selector, args) {
19721971
newtgt[l] = target_object[l];
19731972
newtgt[newtgt.length - 1] = { name: target_name, lst: makeMethodsList(object_class) };
19741973

1975-
if (!scanBranches(branch.fBranches, newtgt, 0)) return null;
1976-
1977-
return item; // this kind of branch does not have baskets and not need to be read
1974+
// this kind of branch does not have baskets and not need to be read
1975+
return scanBranches(branch.fBranches, newtgt, 0) ? item : null;
19781976
} else if (is_brelem && (nb_leaves === 1) && (leaf.fName === branch.fName) && (branch.fID === -1)) {
19791977
elem = createStreamerElement(target_name, branch.fClassName);
19801978

@@ -2774,7 +2772,8 @@ function treeIOTest(tree, args) {
27742772
const branches = [], names = [], nchilds = [];
27752773

27762774
function collectBranches(obj, prntname = '') {
2777-
if (!obj?.fBranches) return 0;
2775+
if (!obj?.fBranches)
2776+
return 0;
27782777

27792778
let cnt = 0;
27802779

@@ -2964,7 +2963,7 @@ function treeHierarchy(tree_node, obj) {
29642963
tree_node._childs = [];
29652964
tree_node._tree = obj; // set reference, will be used later by TTree::Draw
29662965

2967-
for (let i = 0; i < obj.fBranches.arr?.length; ++i)
2966+
for (let i = 0; i < obj.fBranches?.arr.length; ++i)
29682967
createBranchItem(tree_node, obj.fBranches.arr[i], obj);
29692968

29702969
return true;

0 commit comments

Comments
 (0)