From d25631016e9c9779f5b293b0fd8239792052290a Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sun, 10 Nov 2013 17:41:05 +0100 Subject: [PATCH] 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 --- WINGs/wfilepanel.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index 8219ee63..6785beb9 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -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; } }