From: Christophe CURIS <christophe.cu...@free.fr> 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.cu...@free.fr> --- WINGs/wfilepanel.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index 8219ee6..6785beb 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; } } -- 1.8.4.rc3 -- To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.