unroll code for early returns, no logic changed intended

Change-Id: Ic1cc63a5fe3ad2c949f91c395c00f5f99bd7602a
This commit is contained in:
Caolán McNamara 2016-12-23 17:53:50 +00:00
parent 6aa482428e
commit 218179ddbf

View File

@ -53,97 +53,95 @@ BitmapBuffer* ImplCreateDIB(
|| nBitCount == 32) || nBitCount == 32)
&& "Unsupported BitCount!"); && "Unsupported BitCount!");
if (!rSize.Width() || !rSize.Height())
return nullptr;
BitmapBuffer* pDIB = nullptr; BitmapBuffer* pDIB = nullptr;
if( rSize.Width() && rSize.Height() ) try
{ {
try pDIB = new BitmapBuffer;
{ }
pDIB = new BitmapBuffer; catch (const std::bad_alloc&)
} {
catch (const std::bad_alloc&) pDIB = nullptr;
{ }
pDIB = nullptr;
}
if( pDIB ) if(!pDIB)
{ return nullptr;
const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0;
switch (nBitCount) const sal_uInt16 nColors = ( nBitCount <= 8 ) ? ( 1 << nBitCount ) : 0;
{
case 1: switch (nBitCount)
pDIB->mnFormat = ScanlineFormat::N1BitLsbPal; {
break; case 1:
case 4: pDIB->mnFormat = ScanlineFormat::N1BitLsbPal;
pDIB->mnFormat = ScanlineFormat::N4BitMsnPal; break;
break; case 4:
case 8: pDIB->mnFormat = ScanlineFormat::N4BitMsnPal;
pDIB->mnFormat = ScanlineFormat::N8BitPal; break;
break; case 8:
case 16: pDIB->mnFormat = ScanlineFormat::N8BitPal;
{ break;
case 16:
{
#ifdef OSL_BIGENDIAN #ifdef OSL_BIGENDIAN
pDIB->mnFormat= ScanlineFormat::N16BitTcMsbMask; pDIB->mnFormat= ScanlineFormat::N16BitTcMsbMask;
#else #else
pDIB->mnFormat= ScanlineFormat::N16BitTcLsbMask; pDIB->mnFormat= ScanlineFormat::N16BitTcLsbMask;
#endif #endif
ColorMaskElement aRedMask(0xf800); ColorMaskElement aRedMask(0xf800);
aRedMask.CalcMaskShift(); aRedMask.CalcMaskShift();
ColorMaskElement aGreenMask(0x07e0); ColorMaskElement aGreenMask(0x07e0);
aGreenMask.CalcMaskShift(); aGreenMask.CalcMaskShift();
ColorMaskElement aBlueMask(0x001f); ColorMaskElement aBlueMask(0x001f);
aBlueMask.CalcMaskShift(); aBlueMask.CalcMaskShift();
pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); pDIB->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask);
break; break;
} }
default: default:
nBitCount = 32; nBitCount = 32;
SAL_FALLTHROUGH; SAL_FALLTHROUGH;
case 32: case 32:
{ {
pDIB->mnFormat = SVP_CAIRO_FORMAT; pDIB->mnFormat = SVP_CAIRO_FORMAT;
break; break;
}
}
pDIB->mnFormat |= ScanlineFormat::TopDown;
pDIB->mnWidth = rSize.Width();
pDIB->mnHeight = rSize.Height();
pDIB->mnScanlineSize = AlignedWidth4Bytes( pDIB->mnWidth * nBitCount );
pDIB->mnBitCount = nBitCount;
if( nColors )
{
pDIB->maPalette = rPal;
pDIB->maPalette.SetEntryCount( nColors );
}
try
{
size_t size = pDIB->mnScanlineSize * pDIB->mnHeight;
pDIB->mpBits = new sal_uInt8[size];
#ifdef __SANITIZE_ADDRESS__
if (!pDIB->mpBits)
{ // can only happen with ASAN allocator_may_return_null=1
delete pDIB;
pDIB = nullptr;
}
else
#endif
{
std::memset(pDIB->mpBits, 0, size);
}
}
catch (const std::bad_alloc&)
{
delete pDIB;
pDIB = nullptr;
}
} }
} }
else
pDIB->mnFormat |= ScanlineFormat::TopDown;
pDIB->mnWidth = rSize.Width();
pDIB->mnHeight = rSize.Height();
pDIB->mnScanlineSize = AlignedWidth4Bytes( pDIB->mnWidth * nBitCount );
pDIB->mnBitCount = nBitCount;
if( nColors )
{
pDIB->maPalette = rPal;
pDIB->maPalette.SetEntryCount( nColors );
}
try
{
size_t size = pDIB->mnScanlineSize * pDIB->mnHeight;
pDIB->mpBits = new sal_uInt8[size];
#ifdef __SANITIZE_ADDRESS__
if (!pDIB->mpBits)
{ // can only happen with ASAN allocator_may_return_null=1
delete pDIB;
pDIB = nullptr;
}
else
#endif
{
std::memset(pDIB->mpBits, 0, size);
}
}
catch (const std::bad_alloc&)
{
delete pDIB;
pDIB = nullptr; pDIB = nullptr;
}
return pDIB; return pDIB;
} }