[
https://issues.apache.org/jira/browse/LUCENE-5805?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Christoph Kaser updated LUCENE-5805:
------------------------------------
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)
{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}
was:
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}
> 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.7.2, 4.9
> 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_ 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)
> {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: [email protected]
For additional commands, e-mail: [email protected]