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

QueryNodeImpl.removeFromParent does a lot of work without any effect

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.7.2, 4.9
    • Fix Version/s: 5.3, 6.0
    • Component/s: modules/queryparser
    • Labels:
      None
    • Lucene Fields:
      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

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: