VirtualBox

Ignore:
Timestamp:
Oct 20, 2016 7:28:31 PM (8 years ago)
Author:
vboxsync
Message:

strprintf.cpp: Apply the same optimizations as was done for strprintf2.cpp.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/string/strprintf.cpp

    r62477 r64343  
    6767{
    6868    PSTRBUFARG  pArg = (PSTRBUFARG)pvArg;
     69    char *pszCur = pArg->psz; /* We actually have to spell this out for VS2010, or it will load for each case. */
    6970
    7071    cbChars = RT_MIN(pArg->cch, cbChars);
    7172    if (cbChars)
    7273    {
    73         memcpy(pArg->psz, pachChars, cbChars);
    7474        pArg->cch -= cbChars;
    75         pArg->psz += cbChars;
     75
     76        /* Note! For VS2010/64 we need at least 7 case statements before it generates a jump table. */
     77        switch (cbChars)
     78        {
     79            default:
     80                memcpy(pszCur, pachChars, cbChars);
     81                break;
     82            case 8: pszCur[7] = pachChars[7];
     83            case 7: pszCur[6] = pachChars[6];
     84            case 6: pszCur[5] = pachChars[5];
     85            case 5: pszCur[4] = pachChars[4];
     86            case 4: pszCur[3] = pachChars[3];
     87            case 3: pszCur[2] = pachChars[2];
     88            case 2: pszCur[1] = pachChars[1];
     89            case 1: pszCur[0] = pachChars[0];
     90            case 0:
     91                break;
     92        }
     93        pArg->psz = pszCur += cbChars;
    7694    }
    77     *pArg->psz = '\0';
     95    *pszCur = '\0';
    7896
    7997    return cbChars;
     
    8199
    82100
     101RTDECL(size_t) RTStrPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...)
     102{
     103    /* Explicitly inline RTStrPrintfV + RTStrPrintfExV here because this is a frequently use API. */
     104    STRBUFARG Arg;
     105    va_list args;
     106    size_t cbRet;
     107
     108    AssertMsgReturn(cchBuffer, ("Excellent idea! Format a string with no space for the output!\n"), 0);
     109    Arg.psz = pszBuffer;
     110    Arg.cch = cchBuffer - 1;
     111
     112    va_start(args, pszFormat);
     113    cbRet = RTStrFormatV(strbufoutput, &Arg, NULL, NULL, pszFormat, args);
     114    va_end(args);
     115
     116    return cbRet;
     117}
     118RT_EXPORT_SYMBOL(RTStrPrintf);
     119
     120
    83121RTDECL(size_t) RTStrPrintfExV(PFNSTRFORMAT pfnFormat, void *pvArg, char *pszBuffer, size_t cchBuffer, const char *pszFormat, va_list args)
    84122{
    85123    STRBUFARG Arg;
    86 
    87     if (!cchBuffer)
    88     {
    89         AssertMsgFailed(("Excellent idea! Format a string with no space for the output!\n"));
    90         return 0;
    91     }
    92 
     124    AssertMsgReturn(cchBuffer, ("Excellent idea! Format a string with no space for the output!\n"), 0);
    93125    Arg.psz = pszBuffer;
    94126    Arg.cch = cchBuffer - 1;
     
    116148RT_EXPORT_SYMBOL(RTStrPrintfEx);
    117149
    118 
    119 RTDECL(size_t) RTStrPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...)
    120 {
    121     va_list args;
    122     size_t cbRet;
    123     va_start(args, pszFormat);
    124     cbRet = RTStrPrintfV(pszBuffer, cchBuffer, pszFormat, args);
    125     va_end(args);
    126     return cbRet;
    127 }
    128 RT_EXPORT_SYMBOL(RTStrPrintf);
    129 
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