VirtualBox

Changeset 55942 in vbox for trunk


Ignore:
Timestamp:
May 19, 2015 11:00:07 PM (10 years ago)
Author:
vboxsync
Message:

Bstr: Replaced RT_UNLIKELY with RT_LIKELY to improve our karma wrt MSC.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/string.cpp

    r52554 r55942  
    5151    size_t cwc;
    5252    int vrc = ::RTStrCalcUtf16LenEx(a_pszSrc, a_cchMax, &cwc);
    53     if (RT_FAILURE(vrc))
    54     {
    55         /* ASSUME: input is valid Utf-8. Fake out of memory error. */
     53    if (RT_SUCCESS(vrc))
     54    {
     55        m_bstr = ::SysAllocStringByteLen(NULL, (unsigned)(cwc * sizeof(OLECHAR)));
     56        if (RT_LIKELY(m_bstr))
     57        {
     58            PRTUTF16 pwsz = (PRTUTF16)m_bstr;
     59            vrc = ::RTStrToUtf16Ex(a_pszSrc, a_cchMax, &pwsz, cwc + 1, NULL);
     60            if (RT_SUCCESS(vrc))
     61                return;
     62
     63            /* This should not happen! */
     64            AssertRC(vrc);
     65            cleanup();
     66        }
     67    }
     68    else /* ASSUME: input is valid Utf-8. Fake out of memory error. */
    5669        AssertLogRelMsgFailed(("%Rrc %.*Rhxs\n", vrc, RTStrNLen(a_pszSrc, a_cchMax), a_pszSrc));
    57         throw std::bad_alloc();
    58     }
    59 
    60     m_bstr = ::SysAllocStringByteLen(NULL, (unsigned)(cwc * sizeof(OLECHAR)));
    61     if (RT_UNLIKELY(!m_bstr))
    62         throw std::bad_alloc();
    63 
    64     PRTUTF16 pwsz = (PRTUTF16)m_bstr;
    65     vrc = ::RTStrToUtf16Ex(a_pszSrc, a_cchMax, &pwsz, cwc + 1, NULL);
    66     if (RT_FAILURE(vrc))
    67     {
    68         /* This should not happen! */
    69         AssertRC(vrc);
    70         cleanup();
    71         throw std::bad_alloc();
    72     }
     70    throw std::bad_alloc();
    7371}
    7472
     
    8179{
    8280    size_t cb = length() + 1;
    83     *pstr = (char*)nsMemory::Alloc(cb);
    84     if (RT_UNLIKELY(!*pstr))
     81    *pstr = (char *)nsMemory::Alloc(cb);
     82    if (RT_LIKELY(*pstr))
     83        memcpy(*pstr, c_str(), cb);
     84    else
    8585        throw std::bad_alloc();
    86     memcpy(*pstr, c_str(), cb);
    8786}
    8887
     
    9089{
    9190    size_t cb = length() + 1;
    92     *pstr = (char*)nsMemory::Alloc(cb);
    93     if (RT_UNLIKELY(!*pstr))
    94         return E_OUTOFMEMORY;
    95     memcpy(*pstr, c_str(), cb);
    96     return S_OK;
     91    *pstr = (char *)nsMemory::Alloc(cb);
     92    if (RT_LIKELY(*pstr))
     93    {
     94        memcpy(*pstr, c_str(), cb);
     95        return S_OK;
     96    }
     97    return E_OUTOFMEMORY;
    9798}
    9899#endif
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