You could of course cache all .desktop files, build a suffix tree or suffix array data structure, and then use longest-prefix matching instead of stat()ing every possibility.
You could of course cache all .desktop files, build a suffix tree or suffix array data structure, and then use longest-prefix matching instead of stat()ing every possibility.