diff options
author | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2016-10-20 19:28:31 +0000 |
---|---|---|
committer | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2016-10-20 19:28:31 +0000 |
commit | 351ae7443366202daf79d74b21fe82c4947bfe15 (patch) | |
tree | 49d2cc769b4931708694d227642bb6f408a17826 /src/VBox/Runtime/common/string/strprintf.cpp | |
parent | 51bc89f394ef56dfc7145efc7107b15e247fb23c (diff) | |
download | VirtualBox-svn-351ae7443366202daf79d74b21fe82c4947bfe15.tar.gz |
strprintf.cpp: Apply the same optimizations as was done for strprintf2.cpp.
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@64343 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src/VBox/Runtime/common/string/strprintf.cpp')
-rw-r--r-- | src/VBox/Runtime/common/string/strprintf.cpp | 62 |
1 files changed, 41 insertions, 21 deletions
diff --git a/src/VBox/Runtime/common/string/strprintf.cpp b/src/VBox/Runtime/common/string/strprintf.cpp index 82d8d5b3eed..f9081f4058b 100644 --- a/src/VBox/Runtime/common/string/strprintf.cpp +++ b/src/VBox/Runtime/common/string/strprintf.cpp @@ -66,30 +66,62 @@ static DECLCALLBACK(size_t) strbufoutput(void *pvArg, const char *pachChars, siz static DECLCALLBACK(size_t) strbufoutput(void *pvArg, const char *pachChars, size_t cbChars) { PSTRBUFARG pArg = (PSTRBUFARG)pvArg; + char *pszCur = pArg->psz; /* We actually have to spell this out for VS2010, or it will load for each case. */ cbChars = RT_MIN(pArg->cch, cbChars); if (cbChars) { - memcpy(pArg->psz, pachChars, cbChars); pArg->cch -= cbChars; - pArg->psz += cbChars; + + /* Note! For VS2010/64 we need at least 7 case statements before it generates a jump table. */ + switch (cbChars) + { + default: + memcpy(pszCur, pachChars, cbChars); + break; + case 8: pszCur[7] = pachChars[7]; + case 7: pszCur[6] = pachChars[6]; + case 6: pszCur[5] = pachChars[5]; + case 5: pszCur[4] = pachChars[4]; + case 4: pszCur[3] = pachChars[3]; + case 3: pszCur[2] = pachChars[2]; + case 2: pszCur[1] = pachChars[1]; + case 1: pszCur[0] = pachChars[0]; + case 0: + break; + } + pArg->psz = pszCur += cbChars; } - *pArg->psz = '\0'; + *pszCur = '\0'; return cbChars; } -RTDECL(size_t) RTStrPrintfExV(PFNSTRFORMAT pfnFormat, void *pvArg, char *pszBuffer, size_t cchBuffer, const char *pszFormat, va_list args) +RTDECL(size_t) RTStrPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...) { + /* Explicitly inline RTStrPrintfV + RTStrPrintfExV here because this is a frequently use API. */ STRBUFARG Arg; + va_list args; + size_t cbRet; - if (!cchBuffer) - { - AssertMsgFailed(("Excellent idea! Format a string with no space for the output!\n")); - return 0; - } + AssertMsgReturn(cchBuffer, ("Excellent idea! Format a string with no space for the output!\n"), 0); + Arg.psz = pszBuffer; + Arg.cch = cchBuffer - 1; + + va_start(args, pszFormat); + cbRet = RTStrFormatV(strbufoutput, &Arg, NULL, NULL, pszFormat, args); + va_end(args); + + return cbRet; +} +RT_EXPORT_SYMBOL(RTStrPrintf); + +RTDECL(size_t) RTStrPrintfExV(PFNSTRFORMAT pfnFormat, void *pvArg, char *pszBuffer, size_t cchBuffer, const char *pszFormat, va_list args) +{ + STRBUFARG Arg; + AssertMsgReturn(cchBuffer, ("Excellent idea! Format a string with no space for the output!\n"), 0); Arg.psz = pszBuffer; Arg.cch = cchBuffer - 1; return RTStrFormatV(strbufoutput, &Arg, pfnFormat, pvArg, pszFormat, args); @@ -115,15 +147,3 @@ RTDECL(size_t) RTStrPrintfEx(PFNSTRFORMAT pfnFormat, void *pvArg, char *pszBuffe } RT_EXPORT_SYMBOL(RTStrPrintfEx); - -RTDECL(size_t) RTStrPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...) -{ - va_list args; - size_t cbRet; - va_start(args, pszFormat); - cbRet = RTStrPrintfV(pszBuffer, cchBuffer, pszFormat, args); - va_end(args); - return cbRet; -} -RT_EXPORT_SYMBOL(RTStrPrintf); - |