<commit_before>package org.opendaylight.yangtools.yang.data.impl.schema.tree;

import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import java.util.Collection;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;

final class RecursiveReplaceCandidateNode extends AbstractDataTreeCandidateNode {
    private final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData;

    public RecursiveReplaceCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
            final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData) {
        super(newData);
        this.oldData = Preconditions.checkNotNull(oldData);
    }

    @Override
    public ModificationType getModificationType() {
        return ModificationType.WRITE;
    }

    @Override
    public Optional<NormalizedNode<?, ?>> getDataAfter() {
        return super.dataOptional();
    }

    @Override
    public Optional<NormalizedNode<?, ?>> getDataBefore() {
        return Optional.<NormalizedNode<?, ?>>of(oldData);
    }

    @Override
    public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
        // FIXME: this is a linear walk. We need a Map of these in order to
        //        do something like getChildMap().get(identifier);
        for (DataTreeCandidateNode c : getChildNodes()) {
            if (identifier.equals(c.getIdentifier())) {
                return c;
            }
        }
        return null;
    }

    @Override
    public Collection<DataTreeCandidateNode> getChildNodes() {
        return deltaChildren(oldData, getData());
    }
}<commit_msg>Fix performance of RecursiveReplaceCandidateNode.getModifiedChild()<commit_after>package org.opendaylight.yangtools.yang.data.impl.schema.tree;

import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import java.util.Collection;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;

final class RecursiveReplaceCandidateNode extends AbstractDataTreeCandidateNode {
    private final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData;

    public RecursiveReplaceCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
            final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData) {
        super(newData);
        this.oldData = Preconditions.checkNotNull(oldData);
    }

    @Override
    public ModificationType getModificationType() {
        return ModificationType.WRITE;
    }

    @Override
    public Optional<NormalizedNode<?, ?>> getDataAfter() {
        return super.dataOptional();
    }

    @Override
    public Optional<NormalizedNode<?, ?>> getDataBefore() {
        return Optional.<NormalizedNode<?, ?>>of(oldData);
    }

    @Override
    public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
        return deltaChild(oldData, getData(), identifier);
    }

    @Override
    public Collection<DataTreeCandidateNode> getChildNodes() {
        return deltaChildren(oldData, getData());
    }
}
{'fraction_non_alphanumeric': 0.1036473366570454, 'fraction_numerical': 0.0, 'mean_word_length': 4.193460490463215, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '24161', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1061, 'n_words': 186}