* [PATCH 2/2] thread: fix parent/child relationships
2016-10-13 3:59 6% ` [PATCH 0/2] thread: fix regressions from Mail::Thread removal Eric Wong
@ 2016-10-13 3:59 7% ` Eric Wong
0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2016-10-13 3:59 UTC (permalink / raw)
To: meta
The ordering change in add_child is critical if $self == $parent
as the {children} hash was lost before this change.
has_descendent can be simplified by walking upwards from the child
instead of downwards from the parent.
This fixes threading regressions introduced in
commit 30100c46326e2eac275e0af13116636701d2537e
("thread: use hash + array instead of hand-rolled linked list")
---
lib/PublicInbox/SearchThread.pm | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/lib/PublicInbox/SearchThread.pm b/lib/PublicInbox/SearchThread.pm
index c6bd999..24a56d2 100644
--- a/lib/PublicInbox/SearchThread.pm
+++ b/lib/PublicInbox/SearchThread.pm
@@ -104,27 +104,21 @@ sub add_child {
if $self == $child;
my $cid = $child->{id};
- $self->{children}->{$cid} = $child;
# reparenting:
if (defined(my $parent = $child->{parent})) {
delete $parent->{children}->{$cid};
}
+ $self->{children}->{$cid} = $child;
$child->{parent} = $self;
}
sub has_descendent {
- my ($cur, $child) = @_;
- my %seen;
- my @q = ($cur->{parent} || $cur);
-
- while (defined($cur = shift @q)) {
- return 1 if $cur == $child;
-
- if (!$seen{$cur}++) {
- push @q, values %{$cur->{children}};
- }
+ my ($self, $child) = @_;
+ while ($child) {
+ return 1 if $self == $child;
+ $child = $child->{parent};
}
0;
}
--
EW
^ permalink raw reply related [relevance 7%]
* [PATCH 0/2] thread: fix regressions from Mail::Thread removal
@ 2016-10-13 3:59 6% ` Eric Wong
2016-10-13 3:59 7% ` [PATCH 2/2] thread: fix parent/child relationships Eric Wong
0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2016-10-13 3:59 UTC (permalink / raw)
To: meta
Eric Wong (2):
thread: reduce indentation level
thread: fix parent/child relationships
lib/PublicInbox/SearchThread.pm | 54 ++++++++++++++++++-----------------------
1 file changed, 24 insertions(+), 30 deletions(-)
--
EW
^ permalink raw reply [relevance 6%]
Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-10-06 8:22 [PATCH 0/17] remove Mail::Thread dependency Eric Wong
2016-10-13 3:59 6% ` [PATCH 0/2] thread: fix regressions from Mail::Thread removal Eric Wong
2016-10-13 3:59 7% ` [PATCH 2/2] thread: fix parent/child relationships Eric Wong
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).