VirtualBox

Changeset 11017 in vbox for trunk/include


Ignore:
Timestamp:
Jul 30, 2008 10:27:27 PM (16 years ago)
Author:
vboxsync
Message:

iprt: Some RTMemAutoPtr optimizations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/mem.h

    r11014 r11017  
    488488
    489489    /**
    490      * Constructor that
     490     * Constructor that allocates memory.
    491491     *
    492492     * @param   a_cElements The number of elements (of the data type) to allocate.
     
    495495     */
    496496    RTMemAutoPtr(size_t a_cElements, bool a_fZeroed = false)
    497         : RTAutoRes<T *, Destruct, RTMemAutoNil<T> >((T *)NULL)
    498     {
    499         alloc(a_cElements, a_fZeroed);
     497        : RTAutoRes<T *, Destruct, RTMemAutoNil<T> >((T *)Allocator(NULL, a_cElements * sizeof(T)))
     498    {
     499        if (a_fZeroed && RT_LIKELY(this->get() != NULL))
     500            memset(this->get(), '\0', a_cElements * sizeof(T));
    500501    }
    501502
     
    509510        this->RTAutoRes<T *, Destruct, RTMemAutoNil<T> >::operator=(aPtr);
    510511        return *this;
    511      }
     512    }
    512513
    513514    /**
     
    557558        this->reset(NULL);
    558559        T *pNewMem = (T *)Allocator(NULL, a_cElements * sizeof(T));
    559         if (a_fZeroed && pNewMem)
     560        if (a_fZeroed && RT_LIKELY(pNewMem != NULL))
    560561            memset(pNewMem, '\0', a_cElements * sizeof(T));
    561562        this->reset(pNewMem);
     
    584585    {
    585586        T *aNewValue = (T *)Allocator(this->get(), a_cElements * sizeof(T));
    586         if (aNewValue != NULL)
     587        if (RT_LIKELY(aNewValue != NULL))
    587588            this->release();
    588589        /* We want this both if aNewValue is non-NULL and if it is NULL. */
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