int start = 0;
while (start < oldSize && start < newSize) {
OT oldChild = oldChildren[start];
NT newChild = newChildren[start];
if (!comparator.typesEqual(oldChild, newChild)) break;
final ThreeState dp = comparator.deepEqual(oldChild, newChild);
if (deeps != null) deeps[start] = dp;
if (dp != ThreeState.YES) {
if (!comparator.hashcodesEqual(oldChild, newChild)) break;
if (dp == ThreeState.UNSURE) {
build(oldChild, newChild, level + 1);
walkedDeep = true;
}
else if (dp == ThreeState.NO) {
myConsumer.nodeReplaced(oldChild, newChild);
}
}
start++;
}
int oldEnd = oldSize - 1;
int newEnd = newSize - 1;
if (oldSize == newSize && start == newSize) {
disposeLevel(oldChildren, oldSize, newChildren, newSize);
return; // No changes at all at this level
}
while (oldEnd >= start && newEnd >= start) {
OT oldChild = oldChildren[oldEnd];
NT newChild = newChildren[newEnd];
if (!comparator.typesEqual(oldChild, newChild)) break;
final ThreeState dp = comparator.deepEqual(oldChild, newChild);
if (deeps != null) deeps[oldEnd] = dp;
if (dp != ThreeState.YES) {
if (!comparator.hashcodesEqual(oldChild, newChild)) break;
if (dp == ThreeState.UNSURE) {
build(oldChild, newChild, level + 1);
walkedDeep = true;
}
else if (dp == ThreeState.NO) {
myConsumer.nodeReplaced(oldChild, newChild);
}
}
oldEnd--;
newEnd--;
}
if (oldSize == newSize) {
for (int i = start; i <= newEnd; i++) {
final OT oldChild = oldChildren[i];
final NT newChild = newChildren[i];
if (comparator.typesEqual(oldChild, newChild)) {
final ThreeState de = deeps[i];
if (de == ThreeState.UNSURE) {
build(oldChild, newChild, level + 1);
}
else if (de == ThreeState.NO || de == null) {
myConsumer.nodeReplaced(oldChild, newChild);