Kaydet (Commit) 16e3daba authored tarafından Michael Stahl's avatar Michael Stahl

vcl: replace alloca() with std::unique_ptr

Change-Id: If0f44ac761afdf50a8e6f5c77023ae5d74fdcad9
üst 2c9a1811
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include <cmath> #include <cmath>
#include <sal/types.h> #include <sal/types.h>
#include <sal/alloca.h>
#include <basegfx/matrix/b2dhommatrix.hxx> #include <basegfx/matrix/b2dhommatrix.hxx>
...@@ -1019,12 +1018,12 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry, ...@@ -1019,12 +1018,12 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
if( !pSalLayout ) if( !pSalLayout )
return 0; return 0;
#if VCL_FLOAT_DEVICE_PIXEL #if VCL_FLOAT_DEVICE_PIXEL
DeviceCoordinate* pDXPixelArray = NULL; std::unique_ptr<DeviceCoordinate[]> pDXPixelArray;
if(pDXAry) if(pDXAry)
{ {
pDXPixelArray = static_cast<DeviceCoordinate*>(alloca(nLen * sizeof(DeviceCoordinate))); pDXPixelArray.reset(new DeviceCoordinate[nLen]);
} }
DeviceCoordinate nWidth = pSalLayout->FillDXArray( pDXPixelArray ); DeviceCoordinate nWidth = pSalLayout->FillDXArray( pDXPixelArray.get() );
int nWidthFactor = pSalLayout->GetUnitsPerPixel(); int nWidthFactor = pSalLayout->GetUnitsPerPixel();
pSalLayout->Release(); pSalLayout->Release();
...@@ -1346,7 +1345,8 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr, ...@@ -1346,7 +1345,8 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr,
pLayoutCache = nullptr; // don't use cache with modified string! pLayoutCache = nullptr; // don't use cache with modified string!
} }
DeviceCoordinate nPixelWidth = (DeviceCoordinate)nLogicalWidth; DeviceCoordinate nPixelWidth = (DeviceCoordinate)nLogicalWidth;
DeviceCoordinate* pDXPixelArray = NULL; std::unique_ptr<DeviceCoordinate[]> xDXPixelArray;
DeviceCoordinate* pDXPixelArray(nullptr);
if( nLogicalWidth && mbMap ) if( nLogicalWidth && mbMap )
{ {
nPixelWidth = LogicWidthToDeviceCoordinate( nLogicalWidth ); nPixelWidth = LogicWidthToDeviceCoordinate( nLogicalWidth );
...@@ -1357,7 +1357,8 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr, ...@@ -1357,7 +1357,8 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr,
if(mbMap) if(mbMap)
{ {
// convert from logical units to font units using a temporary array // convert from logical units to font units using a temporary array
pDXPixelArray = static_cast<DeviceCoordinate*>(alloca( nLen * sizeof(DeviceCoordinate) )); xDXPixelArray.reset(new DeviceCoordinate[nLen]);
pDXPixelArray = xDXPixelArray.get();
// using base position for better rounding a.k.a. "dancing characters" // using base position for better rounding a.k.a. "dancing characters"
DeviceCoordinate nPixelXOfs = LogicWidthToDeviceCoordinate( rLogicalPos.X() ); DeviceCoordinate nPixelXOfs = LogicWidthToDeviceCoordinate( rLogicalPos.X() );
for( int i = 0; i < nLen; ++i ) for( int i = 0; i < nLen; ++i )
...@@ -1368,7 +1369,8 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr, ...@@ -1368,7 +1369,8 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr,
else else
{ {
#if VCL_FLOAT_DEVICE_PIXEL #if VCL_FLOAT_DEVICE_PIXEL
pDXPixelArray = static_cast<DeviceCoordinate*>(alloca( nLen * sizeof(DeviceCoordinate) )); xDXPixelArray.reset(new DeviceCoordinate[nLen]);
pDXPixelArray = xDXPixelArray.get();
for( int i = 0; i < nLen; ++i ) for( int i = 0; i < nLen; ++i )
{ {
pDXPixelArray[i] = pDXArray[i]; pDXPixelArray[i] = pDXArray[i];
...@@ -1693,8 +1695,8 @@ void OutputDevice::ImplDrawText( OutputDevice& rTargetDevice, const Rectangle& r ...@@ -1693,8 +1695,8 @@ void OutputDevice::ImplDrawText( OutputDevice& rTargetDevice, const Rectangle& r
long nMnemonicY; long nMnemonicY;
DeviceCoordinate nMnemonicWidth; DeviceCoordinate nMnemonicWidth;
long* pCaretXArray = static_cast<long*>(alloca( 2 * sizeof(long) * nLineLen )); std::unique_ptr<long[]> const pCaretXArray(new long[2 * nLineLen]);
/*sal_Bool bRet =*/ _rLayout.GetCaretPositions( aStr, pCaretXArray, /*sal_Bool bRet =*/ _rLayout.GetCaretPositions( aStr, pCaretXArray.get(),
nIndex, nLineLen ); nIndex, nLineLen );
long lc_x1 = pCaretXArray[2*(nMnemonicPos - nIndex)]; long lc_x1 = pCaretXArray[2*(nMnemonicPos - nIndex)];
long lc_x2 = pCaretXArray[2*(nMnemonicPos - nIndex)+1]; long lc_x2 = pCaretXArray[2*(nMnemonicPos - nIndex)+1];
...@@ -1762,8 +1764,8 @@ void OutputDevice::ImplDrawText( OutputDevice& rTargetDevice, const Rectangle& r ...@@ -1762,8 +1764,8 @@ void OutputDevice::ImplDrawText( OutputDevice& rTargetDevice, const Rectangle& r
DeviceCoordinate nMnemonicWidth = 0; DeviceCoordinate nMnemonicWidth = 0;
if ( nMnemonicPos != -1 ) if ( nMnemonicPos != -1 )
{ {
long* pCaretXArray = static_cast<long*>(alloca( 2 * sizeof(long) * aStr.getLength() )); std::unique_ptr<long[]> const pCaretXArray(new long[2 * aStr.getLength()]);
/*sal_Bool bRet =*/ _rLayout.GetCaretPositions( aStr, pCaretXArray, 0, aStr.getLength() ); /*sal_Bool bRet =*/ _rLayout.GetCaretPositions( aStr, pCaretXArray.get(), 0, aStr.getLength() );
long lc_x1 = pCaretXArray[2*(nMnemonicPos)]; long lc_x1 = pCaretXArray[2*(nMnemonicPos)];
long lc_x2 = pCaretXArray[2*(nMnemonicPos)+1]; long lc_x2 = pCaretXArray[2*(nMnemonicPos)+1];
nMnemonicWidth = rTargetDevice.LogicWidthToDeviceCoordinate( std::abs(lc_x1 - lc_x2) ); nMnemonicWidth = rTargetDevice.LogicWidthToDeviceCoordinate( std::abs(lc_x1 - lc_x2) );
...@@ -2213,8 +2215,8 @@ void OutputDevice::DrawCtrlText( const Point& rPos, const OUString& rStr, ...@@ -2213,8 +2215,8 @@ void OutputDevice::DrawCtrlText( const Point& rPos, const OUString& rStr,
nMnemonicPos = nLen-1; nMnemonicPos = nLen-1;
} }
long* pCaretXArray = static_cast<long*>(alloca( 2 * sizeof(long) * nLen )); std::unique_ptr<long[]> const pCaretXArray(new long[2 * nLen]);
/*sal_Bool bRet =*/ GetCaretPositions( aStr, pCaretXArray, nIndex, nLen ); /*sal_Bool bRet =*/ GetCaretPositions( aStr, pCaretXArray.get(), nIndex, nLen );
long lc_x1 = pCaretXArray[ 2*(nMnemonicPos - nIndex) ]; long lc_x1 = pCaretXArray[ 2*(nMnemonicPos - nIndex) ];
long lc_x2 = pCaretXArray[ 2*(nMnemonicPos - nIndex)+1 ]; long lc_x2 = pCaretXArray[ 2*(nMnemonicPos - nIndex)+1 ];
nMnemonicWidth = ::abs((int)(lc_x1 - lc_x2)); nMnemonicWidth = ::abs((int)(lc_x1 - lc_x2));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment