1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-27 01:03:26 +01:00

count_friendlist is too inefficient to use that way

This commit is contained in:
Jfreegman 2014-02-07 23:28:17 -05:00
parent 42cd80efe9
commit bd4b430fbb

View File

@ -21,6 +21,7 @@ extern ToxWindow *prompt;
static int max_friends_index = 0; /* marks the index of the last friend in friends array */ static int max_friends_index = 0; /* marks the index of the last friend in friends array */
static int num_selected = 0; static int num_selected = 0;
static int num_friends = 0;
ToxicFriend friends[MAX_FRIENDS_NUM]; ToxicFriend friends[MAX_FRIENDS_NUM];
static int friendlist_index[MAX_FRIENDS_NUM] = {0}; static int friendlist_index[MAX_FRIENDS_NUM] = {0};
@ -49,7 +50,7 @@ void sort_friendlist_index(Tox *m)
friendlist_index[n++] = friends[i].num; friendlist_index[n++] = friends[i].num;
} }
qsort(friendlist_index, tox_count_friendlist(m), sizeof(int), index_name_cmp); qsort(friendlist_index, num_friends, sizeof(int), index_name_cmp);
} }
static void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str, uint16_t len) static void friendlist_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *str, uint16_t len)
@ -138,6 +139,8 @@ static void friendlist_onFriendAdded(ToxWindow *self, Tox *m, int num, bool sort
friends[i].namelength = strlen(friends[i].name) + 1; friends[i].namelength = strlen(friends[i].name) + 1;
} }
num_friends = tox_count_friendlist(m);
if (i == max_friends_index) if (i == max_friends_index)
++max_friends_index; ++max_friends_index;
@ -200,8 +203,6 @@ static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int num, uint8_t *
static void select_friend(ToxWindow *self, Tox *m, wint_t key) static void select_friend(ToxWindow *self, Tox *m, wint_t key)
{ {
int num_friends = tox_count_friendlist(m);
if (key == KEY_UP) { if (key == KEY_UP) {
if (--num_selected < 0) if (--num_selected < 0)
num_selected = num_friends - 1; num_selected = num_friends - 1;
@ -223,10 +224,9 @@ static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key)
} }
max_friends_index = i; max_friends_index = i;
num_friends = tox_count_friendlist(m);
/* make sure num_selected stays within num_friends range */ /* make sure num_selected stays within num_friends range */
int num_friends = tox_count_friendlist(m);
if (num_friends && num_selected == num_friends) if (num_friends && num_selected == num_friends)
--num_selected; --num_selected;
@ -236,7 +236,7 @@ static void delete_friend(Tox *m, ToxWindow *self, int f_num, wint_t key)
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key) static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
{ {
if (tox_count_friendlist(m) == 0) if (num_friends == 0)
return; return;
int f = friendlist_index[num_selected]; int f = friendlist_index[num_selected];
@ -273,7 +273,6 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
getmaxyx(self->window, y2, x2); getmaxyx(self->window, y2, x2);
bool fix_statuses = x2 != self->x; /* true if window x axis has changed */ bool fix_statuses = x2 != self->x; /* true if window x axis has changed */
int num_friends = tox_count_friendlist(m);
wattron(self->window, COLOR_PAIR(CYAN)); wattron(self->window, COLOR_PAIR(CYAN));
wprintw(self->window, " Open a chat window with the"); wprintw(self->window, " Open a chat window with the");