1
0
mirror of https://github.com/irssi/irssi.git synced 2025-01-03 14:56:47 -05:00

sort windows_seq helpers to top

This commit is contained in:
ailin-nemui 2016-12-20 21:36:56 +01:00
parent 03f5dc63fe
commit 9a018a782c

View File

@ -42,6 +42,12 @@ static int daytag;
static int daycheck; /* 0 = don't check, 1 = time is 00:00, check,
2 = time is 00:00, already checked */
static int window_refnum_lookup(WINDOW_REC *window, void *refnum_p)
{
int refnum = GPOINTER_TO_INT(refnum_p);
return window->refnum == refnum ? 0 : window->refnum < refnum ? -1 : 1;
}
static GSequenceIter *windows_seq_begin(void)
{
return g_sequence_get_begin_iter(windows_seq);
@ -52,6 +58,42 @@ static GSequenceIter *windows_seq_end(void)
return g_sequence_get_end_iter(windows_seq);
}
static GSequenceIter *windows_seq_insert(WINDOW_REC *rec)
{
return g_sequence_insert_sorted(windows_seq, rec, (GCompareDataFunc)window_refnum_cmp, NULL);
}
static GSequenceIter *windows_seq_refnum_lookup(int refnum)
{
return g_sequence_lookup(windows_seq, GINT_TO_POINTER(refnum), (GCompareDataFunc)window_refnum_lookup, NULL);
}
static void windows_seq_changed(GSequenceIter *iter)
{
g_sequence_sort_changed(iter, (GCompareDataFunc)window_refnum_cmp, NULL);
}
static GSequenceIter *windows_seq_window_lookup(WINDOW_REC *rec)
{
return g_sequence_lookup(windows_seq, rec, (GCompareDataFunc)window_refnum_cmp, NULL);
}
/* search to the numerically right iterator of refnum */
static GSequenceIter *windows_seq_refnum_search_right(int refnum)
{
return g_sequence_search(windows_seq, GINT_TO_POINTER(refnum), (GCompareDataFunc)window_refnum_lookup, NULL);
}
/* we want to find the numerically left iterator of refnum, so we
search the right of the previous refnum. but we need to figure out
the case where the iterator is already at the beginning, i.e
iter->refnum >= refnum */
static GSequenceIter *windows_seq_refnum_search_left(int refnum)
{
GSequenceIter *iter = windows_seq_refnum_search_right(refnum - 1);
return iter == windows_seq_begin() ? NULL : g_sequence_iter_prev(iter);
}
static int window_get_new_refnum(void)
{
WINDOW_REC *win;
@ -75,11 +117,6 @@ static int window_get_new_refnum(void)
return refnum;
}
static GSequenceIter *windows_seq_insert(WINDOW_REC *rec)
{
return g_sequence_insert_sorted(windows_seq, rec, (GCompareDataFunc)window_refnum_cmp, NULL);
}
WINDOW_REC *window_create(WI_ITEM_REC *item, int automatic)
{
WINDOW_REC *rec;
@ -114,22 +151,6 @@ static void window_set_refnum0(WINDOW_REC *window, int refnum)
signal_emit("window refnum changed", 2, window, GINT_TO_POINTER(old_refnum));
}
static int window_refnum_lookup(WINDOW_REC *window, void *refnum_p)
{
int refnum = GPOINTER_TO_INT(refnum_p);
return window->refnum == refnum ? 0 : window->refnum < refnum ? -1 : 1;
}
static GSequenceIter *windows_seq_refnum_lookup(int refnum)
{
return g_sequence_lookup(windows_seq, GINT_TO_POINTER(refnum), (GCompareDataFunc)window_refnum_lookup, NULL);
}
static void windows_seq_changed(GSequenceIter *iter)
{
g_sequence_sort_changed(iter, (GCompareDataFunc)window_refnum_cmp, NULL);
}
/* removed_refnum was removed from the windows list, pack the windows so
there won't be any holes. If there is any holes after removed_refnum,
leave the windows behind it alone. */
@ -155,11 +176,6 @@ static void windows_pack(int removed_refnum)
}
}
static GSequenceIter *windows_seq_window_lookup(WINDOW_REC *rec)
{
return g_sequence_lookup(windows_seq, rec, (GCompareDataFunc)window_refnum_cmp, NULL);
}
void window_destroy(WINDOW_REC *window)
{
GSequenceIter *iter;
@ -466,22 +482,6 @@ WINDOW_REC *window_find_item(SERVER_REC *server, const char *name)
return window_item_window(item);
}
/* search to the numerically right iterator of refnum */
static GSequenceIter *windows_seq_refnum_search_right(int refnum)
{
return g_sequence_search(windows_seq, GINT_TO_POINTER(refnum), (GCompareDataFunc)window_refnum_lookup, NULL);
}
/* we want to find the numerically left iterator of refnum, so we
search the right of the previous refnum. but we need to figure out
the case where the iterator is already at the beginning, i.e
iter->refnum >= refnum */
static GSequenceIter *windows_seq_refnum_search_left(int refnum)
{
GSequenceIter *iter = windows_seq_refnum_search_right(refnum - 1);
return iter == windows_seq_begin() ? NULL : g_sequence_iter_prev(iter);
}
int window_refnum_prev(int refnum, int wrap)
{
WINDOW_REC *rec;