Jump to content

Faster Variant::Concat in variant_datatype.cpp


Recommended Posts

void Variant::Concat(Variant &vOp2)
{
    char    *szTempString;
    const char  *szOp2;
    int nOldLen;                    //ADDED

    // This must be a string type
    ChangeToString();

    // Ensure that the other variant has a valid string value and
    // the m_nStrLen m_nStrAlloc variables - VERY IMPORTANT
    szOp2 = vOp2.szValue();
    nOldLen = m_nStrLen;            //ADDED

    // Get new total string length
    m_nStrLen += vOp2.m_nStrLen;

    // Do we have enough space for the concat?
    if ( (m_nStrLen+1) > m_nStrAlloc)           // +1 for \0
    {
        // Create DOUBLE the space we need (room to grow)
        m_nStrAlloc = (m_nStrLen << 1) + 1;

        szTempString    = new char[m_nStrAlloc];

        strcpy(szTempString, m_szValue);
//      strcat(szTempString, szOp2);                        //REMOVED
        strcpy(szTempString + nOldLen, szOp2);  //ADDED

        delete [] m_szValue;
        m_szValue   = szTempString;
    }
    else
//      strcat(szTempString, szOp2);                        //REMOVED
        strcpy(szTempString + nOldLen, szOp2);  //ADDED


} // Concat()

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...