VirtualBox

Changeset 93059 in vbox


Ignore:
Timestamp:
Dec 22, 2021 2:29:22 PM (3 years ago)
Author:
vboxsync
Message:

IPRT/utf8-win.cpp: Optimize string conversion from/to process codepage to UTF-8 if the codepage is UTF-8. This should be more likely after r149060, at least on more recent windows versions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/utf8-win.cpp

    r82968 r93059  
    5050    Assert(ppszString);
    5151    Assert(pszString);
     52    *ppszString = NULL;
    5253
    5354    /*
    54      * Check for zero length input string.
     55     * If the ANSI codepage (CP_ACP) is UTF-8, no translation is needed.
     56     * Same goes for empty strings.
    5557     */
    56     if (cchString < 1 || !*pszString)
     58    if (   cchString == 0
     59        || *pszString == '\0')
     60        return RTStrDupNExTag(ppszString, pszString, 0, pszTag);
     61    if (GetACP() == CP_UTF8)
    5762    {
    58         *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag);
    59         if (*ppszString)
    60             return VINF_SUCCESS;
    61         return VERR_NO_TMP_MEMORY;
     63        int rc = RTStrValidateEncodingEx(pszString, cchString, 0);
     64        AssertRCReturn(rc, rc);
     65        return RTStrDupNExTag(ppszString, pszString, cchString, pszTag);
    6266    }
    63 
    64     *ppszString = NULL;
    6567
    6668    /*
     
    122124    *ppszString = NULL;
    123125
     126    /*
     127     * If the ANSI codepage (CP_ACP) is UTF-8, no translation is needed.
     128     * Same goes for empty strings.
     129     */
     130    if (*pszString == '\0')
     131        return RTStrDupExTag(ppszString, pszString, pszTag);
     132    if (GetACP() == CP_UTF8)
     133    {
     134        int rc = RTStrValidateEncoding(pszString);
     135        AssertRCReturn(rc, rc);
     136        return RTStrDupExTag(ppszString, pszString, pszTag);
     137    }
     138
    124139    /** @todo is there a quicker way? Currently: ACP -> UTF-16 -> UTF-8 */
    125 
    126     size_t cch = strlen(pszString);
    127     if (cch <= 0)
    128     {
    129         /* zero length string passed. */
    130         *ppszString = (char *)RTMemTmpAllocZTag(sizeof(char), pszTag);
    131         if (*ppszString)
    132             return VINF_SUCCESS;
    133         return VERR_NO_TMP_MEMORY;
    134     }
    135140
    136141    /*
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