Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-5805

QueryNodeImpl.removeFromParent does a lot of work without any effect

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.7.2, 4.9
    • 5.3, 6.0
    • modules/queryparser
    • None
    • New

    Description

      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 now 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)

      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;
          }
        }
      

      Attachments

        1. LUCENE-5805.patch
          4 kB
          Cao Manh Dat

        Issue Links

          Activity

            People

              mikemccand Michael McCandless
              christophk Christoph Kaser
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: