mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-10 07:44:14 +01:00
WINGs: Minor improvments in 'closestListItem' function
The check on length of string before comparing is not necessary because this will be checked as part of strcmp; the check won't save time and may actually cost. As the number of element in the array is not going to change during the loop, took the call to 'WMGetArrayItemCount' outside the loop to be faster (and ease compiler's optimisation work). Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
committed by
Carlos R. Mafra
parent
10953b3a7e
commit
d25631016e
@@ -93,16 +93,16 @@ static int closestListItem(WMList * list, const char *text, Bool exact)
|
||||
{
|
||||
WMListItem *item;
|
||||
WMArray *items = WMGetListItems(list);
|
||||
int i, len = strlen(text);
|
||||
int i, nb_item, len = strlen(text);
|
||||
|
||||
if (len == 0)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < WMGetArrayItemCount(items); i++) {
|
||||
nb_item = WMGetArrayItemCount(items);
|
||||
for (i = 0; i < nb_item; i++) {
|
||||
item = WMGetFromArray(items, i);
|
||||
if (strlen(item->text) >= len &&
|
||||
((exact && strcmp(item->text, text) == 0) ||
|
||||
(!exact && strncmp(item->text, text, len) == 0))) {
|
||||
if ((exact && strcmp(item->text, text) == 0) ||
|
||||
(!exact && strncmp(item->text, text, len) == 0)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user