Skip to content

Commit

Permalink
src/filemanager/dir.c: minor sort optimization.
Browse files Browse the repository at this point in the history
Get rid of sort condition double check.

Condition

    ad == bd || panels_options.mix_all_files

was checked twice: first in sort_xxx(), then in sort_name() called in
sort_xxx().

Now this condition is checked in sort_xxx() only.

Signed-off-by: Andrew Borodin <[email protected]>
  • Loading branch information
aborodin committed Jun 5, 2022
1 parent f5399c6 commit 1b93bae
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions src/filemanager/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ key_collate (const char *t1, const char *t2)
return ret;
}

/* --------------------------------------------------------------------------------------------- */

static inline int
compare_by_names (file_entry_t * a, file_entry_t * b)
{
/* create key if does not exist, key will be freed after sorting */
if (a->sort_key == NULL)
a->sort_key = str_create_key_for_filename (a->fname->str, case_sensitive);
if (b->sort_key == NULL)
b->sort_key = str_create_key_for_filename (b->fname->str, case_sensitive);

return key_collate (a->sort_key, b->sort_key);
}

/* --------------------------------------------------------------------------------------------- */
/**
* clear keys, should be call after sorting is finished.
Expand Down Expand Up @@ -336,15 +350,7 @@ sort_name (file_entry_t * a, file_entry_t * b)
int bd = MY_ISDIR (b);

if (ad == bd || panels_options.mix_all_files)
{
/* create key if does not exist, key will be freed after sorting */
if (a->sort_key == NULL)
a->sort_key = str_create_key_for_filename (a->fname->str, case_sensitive);
if (b->sort_key == NULL)
b->sort_key = str_create_key_for_filename (b->fname->str, case_sensitive);

return key_collate (a->sort_key, b->sort_key);
}
return compare_by_names (a, b);

return bd - ad;
}
Expand All @@ -365,7 +371,7 @@ sort_vers (file_entry_t * a, file_entry_t * b)
if (result != 0)
return result * reverse;

return sort_name (a, b);
return compare_by_names (a, b);
}

return bd - ad;
Expand All @@ -392,7 +398,7 @@ sort_ext (file_entry_t * a, file_entry_t * b)
if (r != 0)
return r * reverse;

return sort_name (a, b);
return compare_by_names (a, b);
}

return bd - ad;
Expand All @@ -413,7 +419,7 @@ sort_time (file_entry_t * a, file_entry_t * b)
if (result != 0)
return result * reverse;

return sort_name (a, b);
return compare_by_names (a, b);
}

return bd - ad;
Expand All @@ -434,7 +440,7 @@ sort_ctime (file_entry_t * a, file_entry_t * b)
if (result != 0)
return result * reverse;

return sort_name (a, b);
return compare_by_names (a, b);
}

return bd - ad;
Expand All @@ -455,7 +461,7 @@ sort_atime (file_entry_t * a, file_entry_t * b)
if (result != 0)
return result * reverse;

return sort_name (a, b);
return compare_by_names (a, b);
}

return bd - ad;
Expand Down Expand Up @@ -490,7 +496,7 @@ sort_size (file_entry_t * a, file_entry_t * b)
if (result != 0)
return result * reverse;

return sort_name (a, b);
return compare_by_names (a, b);
}

return bd - ad;
Expand Down

0 comments on commit 1b93bae

Please sign in to comment.