]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: improve readability around walk_thread
authorEric Wong <e@yhbt.net>
Sat, 25 Jan 2020 04:44:51 +0000 (04:44 +0000)
committerEric Wong <e@yhbt.net>
Mon, 27 Jan 2020 02:59:09 +0000 (02:59 +0000)
Pass \&coderefs explicitly to walk_thread, and add some
prototypes + comments to describe what goes on.

lib/PublicInbox/SearchView.pm
lib/PublicInbox/View.pm

index 584b88ed5d4e03b06e5f64a326a83d20ca86e5e9..94a55b8d8a3b1a3cbac5b2b569c2f90160c7de88 100644 (file)
@@ -287,7 +287,7 @@ sub mset_thread {
        # reduce hash lookups in skel_dump
        $ctx->{-obfuscate} = $ctx->{-inbox}->{obfuscate};
        PublicInbox::View::walk_thread($rootset, $ctx,
        # reduce hash lookups in skel_dump
        $ctx->{-obfuscate} = $ctx->{-inbox}->{obfuscate};
        PublicInbox::View::walk_thread($rootset, $ctx,
-               *PublicInbox::View::pre_thread);
+               \&PublicInbox::View::pre_thread);
 
        @$msgs = reverse @$msgs if $r;
        $ctx->{msgs} = $msgs;
 
        @$msgs = reverse @$msgs if $r;
        $ctx->{msgs} = $msgs;
index d8a008c7ffe01bf29862c65a3664e8a04a4b4afc..040604b08b926552aa797725e3960bebeeacb0ee 100644 (file)
@@ -385,7 +385,8 @@ sub _th_index_lite {
        $rv .= $pad ."<a\nhref=#r$id>$s_s, $s_c; $ctx->{s_nr}</a>\n";
 }
 
        $rv .= $pad ."<a\nhref=#r$id>$s_s, $s_c; $ctx->{s_nr}</a>\n";
 }
 
-sub walk_thread {
+# non-recursive thread walker
+sub walk_thread ($$$) {
        my ($rootset, $ctx, $cb) = @_;
        my @q = map { (0, $_, -1) } @$rootset;
        while (@q) {
        my ($rootset, $ctx, $cb) = @_;
        my @q = map { (0, $_, -1) } @$rootset;
        while (@q) {
@@ -398,7 +399,7 @@ sub walk_thread {
        }
 }
 
        }
 }
 
-sub pre_thread  {
+sub pre_thread  { # walk_thread callback
        my ($ctx, $level, $node, $idx) = @_;
        $ctx->{mapping}->{$node->{id}} = [ '', $node, $idx, $level ];
        skel_dump($ctx, $level, $node);
        my ($ctx, $level, $node, $idx) = @_;
        $ctx->{mapping}->{$node->{id}} = [ '', $node, $idx, $level ];
        skel_dump($ctx, $level, $node);
@@ -478,7 +479,7 @@ sub thread_html {
 
        # reduce hash lookups in pre_thread->skel_dump
        $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
 
        # reduce hash lookups in pre_thread->skel_dump
        $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
-       walk_thread($rootset, $ctx, *pre_thread);
+       walk_thread($rootset, $ctx, \&pre_thread);
 
        $skel .= '</pre>';
        return stream_thread($rootset, $ctx) unless $ctx->{flat};
 
        $skel .= '</pre>';
        return stream_thread($rootset, $ctx) unless $ctx->{flat};
@@ -761,7 +762,7 @@ sub thread_skel {
 
        # reduce hash lookups in skel_dump
        $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
 
        # reduce hash lookups in skel_dump
        $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
-       walk_thread(thread_results($ctx, $msgs), $ctx, *skel_dump);
+       walk_thread(thread_results($ctx, $msgs), $ctx, \&skel_dump);
 
        $ctx->{parent_msg} = $parent;
 }
 
        $ctx->{parent_msg} = $parent;
 }
@@ -912,7 +913,7 @@ sub thread_results {
        if (defined($mid) && scalar(@$rootset) > 1) {
                $ctx->{root_idx} = -1;
                my $nr = scalar @$msgs;
        if (defined($mid) && scalar(@$rootset) > 1) {
                $ctx->{root_idx} = -1;
                my $nr = scalar @$msgs;
-               walk_thread($rootset, $ctx, *find_mid_root);
+               walk_thread($rootset, $ctx, \&find_mid_root);
                my $idx = $ctx->{found_mid_at};
                if (defined($idx) && $idx != 0) {
                        my $tip = splice(@$rootset, $idx, 1);
                my $idx = $ctx->{found_mid_at};
                if (defined($idx) && $idx != 0) {
                        my $tip = splice(@$rootset, $idx, 1);
@@ -949,7 +950,7 @@ sub dedupe_subject {
        $omit;
 }
 
        $omit;
 }
 
-sub skel_dump {
+sub skel_dump { # walk_thread callback
        my ($ctx, $level, $node) = @_;
        my $smsg = $node->{smsg} or return _skel_ghost($ctx, $level, $node);
 
        my ($ctx, $level, $node) = @_;
        my $smsg = $node->{smsg} or return _skel_ghost($ctx, $level, $node);
 
@@ -1065,7 +1066,7 @@ sub sort_ds {
 
 # accumulate recent topics if search is supported
 # returns 200 if done, 404 if not
 
 # accumulate recent topics if search is supported
 # returns 200 if done, 404 if not
-sub acc_topic {
+sub acc_topic { # walk_thread callback
        my ($ctx, $level, $node) = @_;
        my $mid = $node->{id};
        my $x = $node->{smsg} || $ctx->{-inbox}->smsg_by_mid($mid);
        my ($ctx, $level, $node) = @_;
        my $mid = $node->{id};
        my $x = $node->{smsg} || $ctx->{-inbox}->smsg_by_mid($mid);
@@ -1231,9 +1232,9 @@ sub index_topics {
        my ($ctx) = @_;
        my $msgs = paginate_recent($ctx, 200); # 200 is our window
        if (@$msgs) {
        my ($ctx) = @_;
        my $msgs = paginate_recent($ctx, 200); # 200 is our window
        if (@$msgs) {
-               walk_thread(thread_results($ctx, $msgs), $ctx, *acc_topic);
+               walk_thread(thread_results($ctx, $msgs), $ctx, \&acc_topic);
        }
        }
-       PublicInbox::WwwStream->response($ctx, dump_topics($ctx), *index_nav);
+       PublicInbox::WwwStream->response($ctx, dump_topics($ctx), \&index_nav);
 }
 
 sub thread_adj_level {
 }
 
 sub thread_adj_level {