From 4d255792201d46b8606e87977efbdc0a3f52fbda Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Mon, 11 Nov 2024 20:36:45 +0000 Subject: [PATCH] JAL-4435 Cache a branch label, re-set ancestor cached labels when name changes --- src/jalview/datamodel/BinaryNode.java | 37 ++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/jalview/datamodel/BinaryNode.java b/src/jalview/datamodel/BinaryNode.java index a842ddf..9390a24 100755 --- a/src/jalview/datamodel/BinaryNode.java +++ b/src/jalview/datamodel/BinaryNode.java @@ -417,16 +417,28 @@ public class BinaryNode return hasLabel() ? label : ""; } + // cache this + private String branchIdentifier = null; + /** * get a concatenation of all node names under this node */ - public String getNodeName() + public String getBranchIdentifier() { - return getNodeName(0); + if (branchIdentifier == null) + { + setBranchIdentifier(true); + } + return branchIdentifier; } - public String getNodeName(int depth) + protected void setBranchIdentifier(boolean force) { + // only set if previously set, or asked for + if (branchIdentifier == null && !force) + { + return; + } StringBuilder sb = new StringBuilder(); if (getName() != null) { @@ -434,18 +446,19 @@ public class BinaryNode } if (left() != null) { - sb.append("::L"); - sb.append(depth); - sb.append("::"); - sb.append(left().getNodeName(depth + 1)); + sb.append("::L:"); + sb.append(left().getBranchIdentifier()); } if (right() != null) { - sb.append("::R"); - sb.append(depth); - sb.append("::"); - sb.append(right.getNodeName(depth + 1)); + sb.append("::R:"); + sb.append(right().getBranchIdentifier()); + } + branchIdentifier = sb.toString(); + // reset ancestors + if (parent() != null) + { + parent.setBranchIdentifier(false); } - return sb.toString(); } } -- 1.7.10.2