Kaydet (Commit) 2c9a1811 authored tarafından Michael Stahl's avatar Michael Stahl

vcl: replace alloca() with std::unique_ptr

Change-Id: I73d27e0e5a8ad0a02579c43f3fd479cb374d6bbd
üst 8f3d411f
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include <cstdio> #include <cstdio>
#include <math.h> #include <math.h>
#include <sal/alloca.h>
#include <salgdi.hxx> #include <salgdi.hxx>
#include <sallayout.hxx> #include <sallayout.hxx>
...@@ -995,7 +994,7 @@ void GenericSalLayout::ApplyDXArray( ImplLayoutArgs& rArgs ) ...@@ -995,7 +994,7 @@ void GenericSalLayout::ApplyDXArray( ImplLayoutArgs& rArgs )
// determine cluster boundaries and x base offset // determine cluster boundaries and x base offset
const int nCharCount = rArgs.mnEndCharPos - rArgs.mnMinCharPos; const int nCharCount = rArgs.mnEndCharPos - rArgs.mnMinCharPos;
int* pLogCluster = static_cast<int*>(alloca( nCharCount * sizeof(int) )); std::unique_ptr<int[]> const pLogCluster(new int[nCharCount]);
size_t i; size_t i;
int n,p; int n,p;
long nBasePointX = -1; long nBasePointX = -1;
...@@ -1030,7 +1029,7 @@ void GenericSalLayout::ApplyDXArray( ImplLayoutArgs& rArgs ) ...@@ -1030,7 +1029,7 @@ void GenericSalLayout::ApplyDXArray( ImplLayoutArgs& rArgs )
} }
// calculate adjusted cluster widths // calculate adjusted cluster widths
long* pNewGlyphWidths = static_cast<long*>(alloca( m_GlyphItems.size() * sizeof(long) )); std::unique_ptr<long[]> const pNewGlyphWidths(new long[m_GlyphItems.size()]);
for( i = 0; i < m_GlyphItems.size(); ++i ) for( i = 0; i < m_GlyphItems.size(); ++i )
pNewGlyphWidths[ i ] = 0; pNewGlyphWidths[ i ] = 0;
...@@ -1294,8 +1293,8 @@ void GenericSalLayout::GetCaretPositions( int nMaxIndex, long* pCaretXArray ) co ...@@ -1294,8 +1293,8 @@ void GenericSalLayout::GetCaretPositions( int nMaxIndex, long* pCaretXArray ) co
sal_Int32 GenericSalLayout::GetTextBreak( DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor ) const sal_Int32 GenericSalLayout::GetTextBreak( DeviceCoordinate nMaxWidth, DeviceCoordinate nCharExtra, int nFactor ) const
{ {
int nCharCapacity = mnEndCharPos - mnMinCharPos; int nCharCapacity = mnEndCharPos - mnMinCharPos;
DeviceCoordinate* pCharWidths = static_cast<DeviceCoordinate*>(alloca( nCharCapacity * sizeof(DeviceCoordinate) )); std::unique_ptr<DeviceCoordinate[]> const pCharWidths(new DeviceCoordinate[nCharCapacity]);
if( !GetCharWidths( pCharWidths ) ) if (!GetCharWidths(pCharWidths.get()))
return -1; return -1;
DeviceCoordinate nWidth = 0; DeviceCoordinate nWidth = 0;
...@@ -1929,13 +1928,13 @@ sal_Int32 MultiSalLayout::GetTextBreak( DeviceCoordinate nMaxWidth, DeviceCoordi ...@@ -1929,13 +1928,13 @@ sal_Int32 MultiSalLayout::GetTextBreak( DeviceCoordinate nMaxWidth, DeviceCoordi
return mpLayouts[0]->GetTextBreak( nMaxWidth, nCharExtra, nFactor ); return mpLayouts[0]->GetTextBreak( nMaxWidth, nCharExtra, nFactor );
int nCharCount = mnEndCharPos - mnMinCharPos; int nCharCount = mnEndCharPos - mnMinCharPos;
DeviceCoordinate* pCharWidths = static_cast<DeviceCoordinate*>(alloca( 2*nCharCount * sizeof(DeviceCoordinate) )); std::unique_ptr<DeviceCoordinate[]> const pCharWidths(new DeviceCoordinate[2 * nCharCount]);
mpLayouts[0]->FillDXArray( pCharWidths ); mpLayouts[0]->FillDXArray( pCharWidths.get() );
for( int n = 1; n < mnLevel; ++n ) for( int n = 1; n < mnLevel; ++n )
{ {
SalLayout& rLayout = *mpLayouts[ n ]; SalLayout& rLayout = *mpLayouts[ n ];
rLayout.FillDXArray( pCharWidths + nCharCount ); rLayout.FillDXArray( &pCharWidths[nCharCount] );
double fUnitMul = mnUnitsPerPixel; double fUnitMul = mnUnitsPerPixel;
fUnitMul /= rLayout.GetUnitsPerPixel(); fUnitMul /= rLayout.GetUnitsPerPixel();
for( int i = 0; i < nCharCount; ++i ) for( int i = 0; i < nCharCount; ++i )
...@@ -1963,19 +1962,19 @@ DeviceCoordinate MultiSalLayout::FillDXArray( DeviceCoordinate* pCharWidths ) co ...@@ -1963,19 +1962,19 @@ DeviceCoordinate MultiSalLayout::FillDXArray( DeviceCoordinate* pCharWidths ) co
DeviceCoordinate nMaxWidth = 0; DeviceCoordinate nMaxWidth = 0;
// prepare merging of fallback levels // prepare merging of fallback levels
DeviceCoordinate* pTempWidths = NULL; std::unique_ptr<DeviceCoordinate[]> pTempWidths;
const int nCharCount = mnEndCharPos - mnMinCharPos; const int nCharCount = mnEndCharPos - mnMinCharPos;
if( pCharWidths ) if( pCharWidths )
{ {
for( int i = 0; i < nCharCount; ++i ) for( int i = 0; i < nCharCount; ++i )
pCharWidths[i] = 0; pCharWidths[i] = 0;
pTempWidths = static_cast<DeviceCoordinate*>(alloca( nCharCount * sizeof(DeviceCoordinate) )); pTempWidths.reset(new DeviceCoordinate[nCharCount]);
} }
for( int n = mnLevel; --n >= 0; ) for( int n = mnLevel; --n >= 0; )
{ {
// query every fallback level // query every fallback level
DeviceCoordinate nTextWidth = mpLayouts[n]->FillDXArray( pTempWidths ); DeviceCoordinate nTextWidth = mpLayouts[n]->FillDXArray( pTempWidths.get() );
if( !nTextWidth ) if( !nTextWidth )
continue; continue;
// merge results from current level // merge results from current level
...@@ -2011,10 +2010,10 @@ void MultiSalLayout::GetCaretPositions( int nMaxIndex, long* pCaretXArray ) cons ...@@ -2011,10 +2010,10 @@ void MultiSalLayout::GetCaretPositions( int nMaxIndex, long* pCaretXArray ) cons
if( mnLevel > 1 ) if( mnLevel > 1 )
{ {
long* pTempPos = static_cast<long*>(alloca( nMaxIndex * sizeof(long) )); std::unique_ptr<long[]> const pTempPos(new long[nMaxIndex]);
for( int n = 1; n < mnLevel; ++n ) for( int n = 1; n < mnLevel; ++n )
{ {
mpLayouts[ n ]->GetCaretPositions( nMaxIndex, pTempPos ); mpLayouts[ n ]->GetCaretPositions( nMaxIndex, pTempPos.get() );
double fUnitMul = mnUnitsPerPixel; double fUnitMul = mnUnitsPerPixel;
fUnitMul /= mpLayouts[n]->GetUnitsPerPixel(); fUnitMul /= mpLayouts[n]->GetUnitsPerPixel();
for( int i = 0; i < nMaxIndex; ++i ) for( int i = 0; i < nMaxIndex; ++i )
......
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