Christoph Kaser created LUCENE-5805:
---------------------------------------

             Summary: QueryNodeImpl.removeFromParent does a lot of work without 
any effect
                 Key: LUCENE-5805
                 URL: https://issues.apache.org/jira/browse/LUCENE-5805
             Project: Lucene - Core
          Issue Type: Bug
          Components: modules/queryparser
    Affects Versions: 4.9, 4.7.2
            Reporter: Christoph Kaser


The method _removeFromParent_ of _QueryNodeImpl_, calls _getChildren_ on the 
parent and removes any occurrence of "this" from the result.

However, since a few releases, _getChildren_ returns a *copy* of the children 
list, so the code has no effect (except creating a copy of the children list 
which will then be thrown away). 
Even worse, since setChildren calls removeFromParent on any previous child, 
setChildren has a complexity of O(n^2) and creates a lot of throw-away copies 
of the children list (for nodes with a lot of children)

{code]
public void removeFromParent() {
    if (this.parent != null) {
      List<QueryNode> parentChildren = this.parent.getChildren();
      Iterator<QueryNode> it = parentChildren.iterator();
      
      while (it.hasNext()) {
        if (it.next() == this) {
          it.remove();
        }
      }
      
      this.parent = null;
    }
  }
{code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org

Reply via email to