Download raw body.
tog cleanup: simplify ref/tree_scroll function calls
On Mon, Nov 30, 2020 at 10:38:31PM +0100, Christian Weisgerber wrote: > simplify the (ref|tree)_scroll_(up|down) function signatures > > Pass only the view state and scroll amount to these functions; > remove unused parameters and those that are contained in the view > state. > > Is this the right direction? > Any style issues? > Did I screw up the conversion? (It tests fine for me.) I cannot spot any problems. Ok :) > diff 34ba691717f92f1469abdb1fdcb04351278668a2 /home/naddy/got > blob - 37a8fe8842d345b89c8c004db5cb3f7c0adcf699 > file + tog/tog.c > --- tog/tog.c > +++ tog/tog.c > @@ -4986,47 +4986,45 @@ draw_tree_entries(struct tog_view *view, > } > > static void > -tree_scroll_up(struct tog_view *view, > - struct got_tree_entry **first_displayed_entry, int maxscroll, > - struct got_tree_object *tree, int isroot) > +tree_scroll_up(struct tog_tree_view_state *s, int maxscroll) > { > struct got_tree_entry *te; > + int isroot = s->tree == s->root; > int i = 0; > > - if (*first_displayed_entry == NULL) > + if (s->first_displayed_entry == NULL) > return; > > - te = got_tree_entry_get_prev(tree, *first_displayed_entry); > + te = got_tree_entry_get_prev(s->tree, s->first_displayed_entry); > while (i++ < maxscroll) { > if (te == NULL) { > if (!isroot) > - *first_displayed_entry = NULL; > + s->first_displayed_entry = NULL; > break; > } > - *first_displayed_entry = te; > - te = got_tree_entry_get_prev(tree, te); > + s->first_displayed_entry = te; > + te = got_tree_entry_get_prev(s->tree, te); > } > } > > static void > -tree_scroll_down(struct got_tree_entry **first_displayed_entry, int maxscroll, > - struct got_tree_entry *last_displayed_entry, > - struct got_tree_object *tree) > +tree_scroll_down(struct tog_tree_view_state *s, int maxscroll) > { > struct got_tree_entry *next, *last; > int n = 0; > > - if (*first_displayed_entry) > - next = got_tree_entry_get_next(tree, *first_displayed_entry); > + if (s->first_displayed_entry) > + next = got_tree_entry_get_next(s->tree, > + s->first_displayed_entry); > else > - next = got_object_tree_get_first_entry(tree); > + next = got_object_tree_get_first_entry(s->tree); > > - last = last_displayed_entry; > + last = s->last_displayed_entry; > while (next && last && n++ < maxscroll) { > - last = got_tree_entry_get_next(tree, last); > + last = got_tree_entry_get_next(s->tree, last); > if (last) { > - *first_displayed_entry = next; > - next = got_tree_entry_get_next(tree, next); > + s->first_displayed_entry = next; > + next = got_tree_entry_get_next(s->tree, next); > } > } > } > @@ -5412,8 +5410,7 @@ input_tree_view(struct tog_view **new_view, struct tog > s->selected--; > break; > } > - tree_scroll_up(view, &s->first_displayed_entry, 1, > - s->tree, s->tree == s->root); > + tree_scroll_up(s, 1); > break; > case KEY_PPAGE: > case CTRL('b'): > @@ -5425,8 +5422,7 @@ input_tree_view(struct tog_view **new_view, struct tog > if (s->first_displayed_entry == NULL) > s->selected = 0; > } > - tree_scroll_up(view, &s->first_displayed_entry, > - MAX(0, view->nlines - 3), s->tree, s->tree == s->root); > + tree_scroll_up(s, MAX(0, view->nlines - 3)); > break; > case 'j': > case KEY_DOWN: > @@ -5438,8 +5434,7 @@ input_tree_view(struct tog_view **new_view, struct tog > == NULL) > /* can't scroll any further */ > break; > - tree_scroll_down(&s->first_displayed_entry, 1, > - s->last_displayed_entry, s->tree); > + tree_scroll_down(s, 1); > break; > case KEY_NPAGE: > case CTRL('f'): > @@ -5450,8 +5445,7 @@ input_tree_view(struct tog_view **new_view, struct tog > s->selected = s->ndisplayed - 1; > break; > } > - tree_scroll_down(&s->first_displayed_entry, view->nlines - 3, > - s->last_displayed_entry, s->tree); > + tree_scroll_down(s, view->nlines - 3); > break; > case KEY_ENTER: > case '\r': > @@ -5853,43 +5847,39 @@ done: > } > > static void > -ref_scroll_up(struct tog_view *view, > - struct tog_reflist_entry **first_displayed_entry, int maxscroll, > - struct tog_reflist_head *refs) > +ref_scroll_up(struct tog_ref_view_state *s, int maxscroll) > { > struct tog_reflist_entry *re; > int i = 0; > > - if (*first_displayed_entry == TAILQ_FIRST(refs)) > + if (s->first_displayed_entry == TAILQ_FIRST(&s->refs)) > return; > > - re = TAILQ_PREV(*first_displayed_entry, tog_reflist_head, entry); > + re = TAILQ_PREV(s->first_displayed_entry, tog_reflist_head, entry); > while (i++ < maxscroll) { > if (re == NULL) > break; > - *first_displayed_entry = re; > + s->first_displayed_entry = re; > re = TAILQ_PREV(re, tog_reflist_head, entry); > } > } > > static void > -ref_scroll_down(struct tog_reflist_entry **first_displayed_entry, int maxscroll, > - struct tog_reflist_entry *last_displayed_entry, > - struct tog_reflist_head *refs) > +ref_scroll_down(struct tog_ref_view_state *s, int maxscroll) > { > struct tog_reflist_entry *next, *last; > int n = 0; > > - if (*first_displayed_entry) > - next = TAILQ_NEXT(*first_displayed_entry, entry); > + if (s->first_displayed_entry) > + next = TAILQ_NEXT(s->first_displayed_entry, entry); > else > - next = TAILQ_FIRST(refs); > + next = TAILQ_FIRST(&s->refs); > > - last = last_displayed_entry; > + last = s->last_displayed_entry; > while (next && last && n++ < maxscroll) { > last = TAILQ_NEXT(last, entry); > if (last) { > - *first_displayed_entry = next; > + s->first_displayed_entry = next; > next = TAILQ_NEXT(next, entry); > } > } > @@ -6204,14 +6194,13 @@ input_ref_view(struct tog_view **new_view, struct tog_ > s->selected--; > break; > } > - ref_scroll_up(view, &s->first_displayed_entry, 1, &s->refs); > + ref_scroll_up(s, 1); > break; > case KEY_PPAGE: > case CTRL('b'): > if (s->first_displayed_entry == TAILQ_FIRST(&s->refs)) > s->selected = 0; > - ref_scroll_up(view, &s->first_displayed_entry, > - MAX(0, view->nlines - 1), &s->refs); > + ref_scroll_up(s, MAX(0, view->nlines - 1)); > break; > case 'j': > case KEY_DOWN: > @@ -6222,8 +6211,7 @@ input_ref_view(struct tog_view **new_view, struct tog_ > if (TAILQ_NEXT(s->last_displayed_entry, entry) == NULL) > /* can't scroll any further */ > break; > - ref_scroll_down(&s->first_displayed_entry, 1, > - s->last_displayed_entry, &s->refs); > + ref_scroll_down(s, 1); > break; > case KEY_NPAGE: > case CTRL('f'): > @@ -6233,8 +6221,7 @@ input_ref_view(struct tog_view **new_view, struct tog_ > s->selected = s->ndisplayed - 1; > break; > } > - ref_scroll_down(&s->first_displayed_entry, > - view->nlines - 1, s->last_displayed_entry, &s->refs); > + ref_scroll_down(s, view->nlines - 1); > break; > case CTRL('l'): > ref_view_free_refs(s); > -- > Christian "naddy" Weisgerber naddy@mips.inka.de > >
tog cleanup: simplify ref/tree_scroll function calls