From 370d1e01ac9a81c10aa1cc3dea256337f94321c9 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 26 Apr 2018 00:01:56 +0000 Subject: fix missing loop check We failed to detect cyclic dependencies, leading to lost thread roots. In this Ruby version, I also screwed up the `seen' hash check in a misguided effort to avoid an extra hash lookup. The same algorithm was recently fixed in public-inbox: https://public-inbox.org/meta/20180425085249.14974-1-e@80x24.org/ Summarizing what happened with public-inbox: this algorithm can still be thrown off when the References: order presented to us is wrong, so sorting messages by age before feeding to Msgthr#add can improve the results. Regardless of ordering, messages should not become "lost" by the algorithm. --- lib/msgthr/container.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/msgthr/container.rb') diff --git a/lib/msgthr/container.rb b/lib/msgthr/container.rb index fbff719..256033b 100644 --- a/lib/msgthr/container.rb +++ b/lib/msgthr/container.rb @@ -64,9 +64,10 @@ class Msgthr::Container end def has_descendent(child) # :nodoc: - seen = Hash.new(0) + seen = {} while child - return true if self == child || (seen[child] += 1) != 0 + return true if self == child || seen[child] + seen[child] = true child = child.parent end false -- cgit v1.2.3-24-ge0c7