Sign in to follow this  
Followers 0
ohgreat

Faster Variant::Concat in variant_datatype.cpp

3 posts in this topic

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()

Share this post


Link to post
Share on other sites



The beta is running with such code already, even using memcpy instead of strcpy.

Thanks for trying to improve AutoIt internals ;)

Share this post


Link to post
Share on other sites

The beta is running with such code already, even using memcpy instead of strcpy.

Thanks for trying to improve AutoIt internals ;)

Great stuff! :P

Share this post


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
Sign in to follow this  
Followers 0