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:
Christophe CURIS authored and Carlos R. Mafra committed 2013-12-30 18:11:04 +00:00
1 parent 10953b3a7e
commit d25631016e
1 file changed
+5 -5
+5 -5
View File
@@ -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;
}
}