protected AbstractImmutableDataContainerNodeBuilder(final AbstractImmutableDataContainerNode<I> node) {
this.nodeIdentifier = node.getIdentifier();
+
+ /*
+ * FIXME: BUG-2402: this call is not what we actually want. We are the
+ * only user of getChildren(), and we really want this to be a
+ * zero-copy operation if we happen to not modify the children.
+ * If we do, we want to perform an efficient copy-on-write before
+ * we make the change.
+ *
+ * With this interface we end up creating a lot of short-lived
+ * objects in case we modify the map -- see checkDirty().
+ */
this.value = node.getChildren();
this.dirty = true;
}
private void checkDirty() {
if (dirty) {
+ /*
+ * FIXME: BUG-2402: This is the second part of the above. Note
+ * that value here is usually a read-only view. Invocation
+ * of this constructor will force instantiation of a wrapper
+ * Map.Entry object, just to make sure this read path does
+ * not modify the map.
+ */
value = new HashMap<>(value);
dirty = false;
}
return children.hashCode();
}
+ /**
+ * DO NOT USE THIS METHOD.
+ *
+ * This is an implementation-internal API and no outside users should use it. If you do,
+ * you are asking for trouble, as the returned object is not guaranteed to conform to
+ * java.util.Map interface.
+ *
+ * @return An unmodifiable view if this node's children.
+ */
public final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> getChildren() {
return children;
}