Sorry for being obsessed with microoptimizations, but I have this.
static int Q(const struct dirent **const First, const struct dirent **const Second) {
const char *const FirstName = (*First)->d_name, *const SecondName = (*Second)->d_name, *const Name() = {FirstName, SecondName};
const unsigned short FirstLen = (unsigned short)strlen(FirstName), SecondLen = (unsigned short)strlen(SecondName), Len() = {FirstLen, SecondLen};
char File(SavesLen+Len(FirstLen > SecondLen)+2), *CurrPtr = memcpy(File, S, SavesLen)+SavesLen;
*CurrPtr++ = '/';
time_t Time(2);
for (unsigned char I = 0; I < 2; I++) {
memcpy(CurrPtr, Name(I), Len(I));
struct stat Stat;
if (stat(File, &Stat)){
return 0;
}
Time(I) = Stat.st_atimespec.tv_sec;
}
return Time(1)-(*Time);
}
This goes in scandir
or qsort
to sort an array of struct dirent *
s by access date. S
is the directory path of the directory whose files are being sorted, and SavesLen
is strlen(S)
. Both are global variables defined and declared and initialized elsewhere. Is there a way to take advantage of local scopes to delete some of the memory earlier? Are there other improvements to be made? Thanks ahead of time.