Fix XImage assignment operator a better way.

This commit is contained in:
Jief L 2020-03-31 00:42:58 +03:00
parent cdf5913c24
commit 2cb912ca74
3 changed files with 20 additions and 13 deletions

View File

@ -2542,7 +2542,6 @@
DEBUG_ON_SERIAL_PORT,
"JCONST=CONST",
NO_MSABI_VA_FUNCS,
"USE_XTHEME=0",
);
HEADER_SEARCH_PATHS = (
$PROJECT_DIR/../../Build/Clover/DEBUG_XCODE8/X64/rEFIt_UEFI/refit/DEBUG,

View File

@ -41,7 +41,8 @@ class XArray
TYPE *data() { return m_data; }
public:
xsize AllocatedSize() const { return m_allocatedSize; }
xsize allocatedSize() const { return m_allocatedSize; }
xsize length() const { return m_len; }
xsize size() const { return m_len; }
void setSize(xsize l);
@ -144,10 +145,22 @@ XArray<TYPE>::XArray(const XArray<TYPE> &anArray)
template<class TYPE>
const XArray<TYPE> &XArray<TYPE>::operator =(const XArray<TYPE> &anArray)
{
xsize ui;
setEmpty();
for ( ui=0 ; ui<anArray.length() ; ui+=1 ) Add(anArray[ui] );
if ( anArray.length() > 0 )
{
CheckSize(anArray.length(), 0);
memcpy(m_data, anArray.m_data, anArray.m_len * sizeof(TYPE));
m_len = anArray.m_len;
}
else
{
setEmpty();
}
//
//
//xsize ui;
//
// setEmpty();
// for ( ui=0 ; ui<anArray.length() ; ui+=1 ) Add(anArray[ui] );
return *this;
}

View File

@ -59,13 +59,8 @@ EFI_STATUS XImage::FromEGImage(const EG_IMAGE* egImage)
XImage& XImage::operator= (const XImage& other)
{
// &other.PixelData[0] won't work if other is empty. So we check.
if ( other.isEmpty() ) {
setEmpty();
}else{
setSizeInPixels(other.GetWidth(), other.GetHeight()); // change the size, ie the number of element in the array. Reaalocate buffer if needed
CopyMem(&PixelData[0], &other.PixelData[0], GetSizeInBytes());
}
setSizeInPixels(other.GetWidth(), other.GetHeight()); // change the size, ie the number of element in the array. Reaalocate buffer if needed
PixelData = other.PixelData;
return *this;
}