/* Lock used to protect the accesses to the HT_IO object */
private final ReentrantReadWriteLock fRwl = new ReentrantReadWriteLock(false);
+ private transient @Nullable List<N> fLatestBranchSnapshot = null;
+
/**
* Create a new State History from scratch, specifying all configuration
* parameters.
* @return The immutable latest branch
*/
@VisibleForTesting
- List<N> getLatestBranch() {
- return ImmutableList.copyOf(fLatestBranch);
+ final List<N> getLatestBranch() {
+ List<N> latestBranchSnapshot = fLatestBranchSnapshot;
+ if (latestBranchSnapshot == null) {
+ synchronized (fLatestBranch) {
+ latestBranchSnapshot = ImmutableList.copyOf(fLatestBranch);
+ fLatestBranchSnapshot = latestBranchSnapshot;
+ }
+ }
+ return latestBranchSnapshot;
}
/**
* insertion
*/
protected final void tryInsertAtNode(E interval, int depth) {
- N targetNode = getLatestBranch().get(depth);
+ N targetNode = fLatestBranch.get(depth);
informInsertingAtDepth(depth);
/* Verify if there is enough room in this node to store this interval */
private final void addSiblingNode(int depth, long newNodeStartTime) {
synchronized (fLatestBranch) {
final long splitTime = fTreeEnd;
+ fLatestBranchSnapshot = null;
if (depth >= fLatestBranch.size()) {
/*