monarch-initiative / owlsim-v3

Ontology Based Profile Matching
17 stars 5 forks source link

Unecessary auto-(un)boxing of intgers in BMKnowledgeBaseOWLAPIImpl #66

Closed julesjacobsen closed 7 years ago

julesjacobsen commented 7 years ago
    protected int getIndexForClassNode(Node<OWLClass> n) {
        Preconditions.checkNotNull(n);
        if (!classNodeToIntegerMap.containsKey(n))
            LOG.error("No such node: " + n);
        return classNodeToIntegerMap.get(n);
    }

is called by

    private Set<Integer> getIntegersForClassSet(NodeSet<OWLClass> nodeset) {
        Set<Integer> bits = new HashSet<>();
        for (Node<OWLClass> n : nodeset.getNodes()) {
            if (n.contains(getOWLNothing()))
                continue;
            bits.add(getIndexForClassNode(n));
        }
        return bits;
    }

So this just ends up converting an Integer to an int back to an Integer many times for each OWLClass and OWLNamedIndividual in each ontology. This is likely using a lot more CPU than required.

getIndexForClassNode is also marked as protected instead of private, but appears to be capable of being private as its only used internally in the class itself being called from private methods. Should this really be the case then it should be safe to return an Integer without breaking anything.

@cmungall is this really a safe change to make?

julesjacobsen commented 7 years ago

done in #70