VirtualBox

Changeset 2993 in kBuild


Ignore:
Timestamp:
Nov 1, 2016 10:41:26 PM (8 years ago)
Author:
bird
Message:

ntstat.c: tiny optimization.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/nt/ntstat.c

    r2985 r2993  
    4646static int birdIsExecutableExtension(const char *pszExt)
    4747{
    48     return  !strcmp(pszExt, "exe")
    49          || !strcmp(pszExt, "cmd")
    50          || !strcmp(pszExt, "bat")
    51          || !strcmp(pszExt, "vbs")
    52          || !strcmp(pszExt, "com")
    53          ;
     48    switch (pszExt[0])
     49    {
     50        default:
     51            return 0;
     52
     53        case 'e': /* exe */
     54            return pszExt[1] == 'x' && pszExt[2] == 'e' && pszExt[3] == '\0';
     55
     56        case 'b': /* bat */
     57            return pszExt[1] == 'a' && pszExt[2] == 't' && pszExt[3] == '\0';
     58
     59        case 'v': /* vbs */
     60            return pszExt[1] == 'v' && pszExt[2] == 's' && pszExt[3] == '\0';
     61
     62        case 'c': /* com and cmd */
     63            return (pszExt[1] == 'o' && pszExt[2] == 'm' && pszExt[3] == '\0')
     64                || (pszExt[1] == 'm' && pszExt[2] == 'd' && pszExt[3] == '\0');
     65    }
    5466}
    5567
     
    7991        return 0;
    8092
    81     /* Copy the extension out and lower case it. */
     93    /* Copy the extension out and lower case it.  Fail immediately on non-alpha chars. */
    8294    for (i = 0; i < cchExt; i++, pszExt++)
    8395    {
    8496        ch = *pszExt;
    85         if (ch >= 'A' && ch <= 'Z')
     97        if (ch >= 'a' && ch <= 'z')
     98        { /* likely */ }
     99        else if (ch >= 'A' && ch <= 'Z')
    86100            ch += 'a' - 'A';
     101        else
     102            return 0;
    87103        szExt[i] = ch;
    88104    }
     
    113129        return 0;
    114130
    115     /* Copy the extension out and lower case it. */
     131    /* Copy the extension out and lower case it.  Fail immediately on non-alpha chars. */
    116132    pwc = &pwcName[cwcName - cchExt];
    117133    for (i = 0; i < cchExt; i++, pwc++)
    118134    {
    119135        WCHAR wc = *pwc;
    120         if (wc >= 'A' && wc <= 'Z')
     136        if (wc >= 'a' && wc <= 'z')
     137        { /* likely */ }
     138        else if (wc >= 'A' && wc <= 'Z')
    121139            wc += 'a' - 'A';
    122         else if (wc > 255)
    123             wc = 255;
     140        else
     141            return 0;
    124142        szExt[i] = (char)wc;
    125143    }
     
    170188        fMode |= S_IWOTH | S_IWGRP | S_IWUSR;
    171189    if (   (fAttribs & FILE_ATTRIBUTE_DIRECTORY)
    172         || (pszName
    173             ? birdIsFileExecutable(pszName)
    174             : birdIsFileExecutableW(pwszName, cbNameW)) )
     190        || (pwszName
     191            ? birdIsFileExecutableW(pwszName, cbNameW)
     192            : birdIsFileExecutable(pszName)) )
    175193        fMode |= S_IXOTH | S_IXGRP | S_IXUSR;
    176194
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette