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

QueryNodeImpl.removeFromParent does a lot of work without any effect

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

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

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment