Kaydet (Commit) 4c171779 authored tarafından Miklos Vajna's avatar Miklos Vajna

Use comphelper::containerToSequence() instead of manual realloc

Change-Id: I88e8050055e53e0da8ac32e049c5ab793096f687
üst de145fb4
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <com/sun/star/text/XText.hpp> #include <com/sun/star/text/XText.hpp>
#include <com/sun/star/text/TextGridMode.hpp> #include <com/sun/star/text/TextGridMode.hpp>
#include <com/sun/star/text/XTextCopy.hpp> #include <com/sun/star/text/XTextCopy.hpp>
#include <comphelper/sequence.hxx>
#include "dmapperLoggers.hxx" #include "dmapperLoggers.hxx"
#include "PropertyMapHelper.hxx" #include "PropertyMapHelper.hxx"
...@@ -65,7 +66,7 @@ PropertyMap::~PropertyMap() ...@@ -65,7 +66,7 @@ PropertyMap::~PropertyMap()
uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharGrabBag) uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharGrabBag)
{ {
if(!m_aValues.getLength() && !m_vMap.empty()) if(m_aValues.empty() && !m_vMap.empty())
{ {
size_t nCharGrabBag = 0; size_t nCharGrabBag = 0;
size_t nParaGrabBag = 0; size_t nParaGrabBag = 0;
...@@ -94,20 +95,7 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharG ...@@ -94,20 +95,7 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharG
nRowGrabBag++; nRowGrabBag++;
} }
// In case there are properties to be grab-bagged and we can have a char grab-bag, allocate one slot for it.
size_t nCharGrabBagSize = 0;
if (bCharGrabBag)
nCharGrabBagSize = nCharGrabBag ? 1 : 0;
size_t nParaGrabBagSize = nParaGrabBag ? 1 : 0;
size_t nCellGrabBagSize = nCellGrabBag ? 1 : 0;
size_t nRowGrabBagSize = nRowGrabBag ? 1 : 0;
// If there are any grab bag properties, we need one slot for them. // If there are any grab bag properties, we need one slot for them.
m_aValues.realloc( m_vMap.size() - nCharGrabBag + nCharGrabBagSize
- nParaGrabBag + nParaGrabBagSize
- nCellGrabBagSaved + nCellGrabBagSize
- nRowGrabBag + nRowGrabBagSize);
::com::sun::star::beans::PropertyValue* pValues = m_aValues.getArray();
uno::Sequence<beans::PropertyValue> aCharGrabBagValues(nCharGrabBag); uno::Sequence<beans::PropertyValue> aCharGrabBagValues(nCharGrabBag);
uno::Sequence<beans::PropertyValue> aParaGrabBagValues(nParaGrabBag); uno::Sequence<beans::PropertyValue> aParaGrabBagValues(nParaGrabBag);
uno::Sequence<beans::PropertyValue> aCellGrabBagValues(nCellGrabBag); uno::Sequence<beans::PropertyValue> aCellGrabBagValues(nCellGrabBag);
...@@ -118,7 +106,6 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharG ...@@ -118,7 +106,6 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharG
beans::PropertyValue* pRowGrabBagValues = aRowGrabBagValues.getArray(); beans::PropertyValue* pRowGrabBagValues = aRowGrabBagValues.getArray();
//style names have to be the first elements within the property sequence //style names have to be the first elements within the property sequence
//otherwise they will overwrite 'hard' attributes //otherwise they will overwrite 'hard' attributes
sal_Int32 nValue = 0;
sal_Int32 nRowGrabBagValue = 0; sal_Int32 nRowGrabBagValue = 0;
sal_Int32 nCellGrabBagValue = 0; sal_Int32 nCellGrabBagValue = 0;
sal_Int32 nParaGrabBagValue = 0; sal_Int32 nParaGrabBagValue = 0;
...@@ -127,24 +114,27 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharG ...@@ -127,24 +114,27 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharG
MapIterator aParaStyleIter = m_vMap.find(PROP_PARA_STYLE_NAME); MapIterator aParaStyleIter = m_vMap.find(PROP_PARA_STYLE_NAME);
if( aParaStyleIter != m_vMap.end()) if( aParaStyleIter != m_vMap.end())
{ {
pValues[nValue].Name = rPropNameSupplier.GetName( aParaStyleIter->first ); beans::PropertyValue aValue;
pValues[nValue].Value = aParaStyleIter->second.getValue(); aValue.Name = rPropNameSupplier.GetName( aParaStyleIter->first );
++nValue; aValue.Value = aParaStyleIter->second.getValue();
m_aValues.push_back(aValue);
} }
MapIterator aCharStyleIter = m_vMap.find(PROP_CHAR_STYLE_NAME); MapIterator aCharStyleIter = m_vMap.find(PROP_CHAR_STYLE_NAME);
if( aCharStyleIter != m_vMap.end()) if( aCharStyleIter != m_vMap.end())
{ {
pValues[nValue].Name = rPropNameSupplier.GetName( aCharStyleIter->first ); beans::PropertyValue aValue;
pValues[nValue].Value = aCharStyleIter->second.getValue(); aValue.Name = rPropNameSupplier.GetName( aCharStyleIter->first );
++nValue; aValue.Value = aCharStyleIter->second.getValue();
m_aValues.push_back(aValue);
} }
MapIterator aNumRuleIter = m_vMap.find(PROP_NUMBERING_RULES); MapIterator aNumRuleIter = m_vMap.find(PROP_NUMBERING_RULES);
if( aNumRuleIter != m_vMap.end()) if( aNumRuleIter != m_vMap.end())
{ {
pValues[nValue].Name = rPropNameSupplier.GetName( aNumRuleIter->first ); beans::PropertyValue aValue;
pValues[nValue].Value = aNumRuleIter->second.getValue(); aValue.Name = rPropNameSupplier.GetName( aNumRuleIter->first );
++nValue; aValue.Value = aNumRuleIter->second.getValue();
m_aValues.push_back(aValue);
} }
MapIterator aMapIter = m_vMap.begin(); MapIterator aMapIter = m_vMap.begin();
for( ; aMapIter != m_vMap.end(); ++aMapIter ) for( ; aMapIter != m_vMap.end(); ++aMapIter )
...@@ -192,39 +182,44 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharG ...@@ -192,39 +182,44 @@ uno::Sequence< beans::PropertyValue > PropertyMap::GetPropertyValues(bool bCharG
} }
else else
{ {
pValues[nValue].Name = rPropNameSupplier.GetName( aMapIter->first ); beans::PropertyValue aValue;
pValues[nValue].Value = aMapIter->second.getValue(); aValue.Name = rPropNameSupplier.GetName( aMapIter->first );
++nValue; aValue.Value = aMapIter->second.getValue();
m_aValues.push_back(aValue);
} }
} }
} }
} }
if (nCharGrabBag && bCharGrabBag) if (nCharGrabBag && bCharGrabBag)
{ {
pValues[nValue].Name = "CharInteropGrabBag"; beans::PropertyValue aValue;
pValues[nValue].Value = uno::makeAny(aCharGrabBagValues); aValue.Name = "CharInteropGrabBag";
++nValue; aValue.Value = uno::makeAny(aCharGrabBagValues);
m_aValues.push_back(aValue);
} }
if (nParaGrabBag) if (nParaGrabBag)
{ {
pValues[nValue].Name = "ParaInteropGrabBag"; beans::PropertyValue aValue;
pValues[nValue].Value = uno::makeAny(aParaGrabBagValues); aValue.Name = "ParaInteropGrabBag";
++nValue; aValue.Value = uno::makeAny(aParaGrabBagValues);
m_aValues.push_back(aValue);
} }
if (nCellGrabBag) if (nCellGrabBag)
{ {
pValues[nValue].Name = "CellInteropGrabBag"; beans::PropertyValue aValue;
pValues[nValue].Value = uno::makeAny(aCellGrabBagValues); aValue.Name = "CellInteropGrabBag";
++nValue; aValue.Value = uno::makeAny(aCellGrabBagValues);
m_aValues.push_back(aValue);
} }
if (nRowGrabBag) if (nRowGrabBag)
{ {
pValues[nValue].Name = "RowInteropGrabBag"; beans::PropertyValue aValue;
pValues[nValue].Value = uno::makeAny(aRowGrabBagValues); aValue.Name = "RowInteropGrabBag";
++nValue; aValue.Value = uno::makeAny(aRowGrabBagValues);
m_aValues.push_back(aValue);
} }
} }
return m_aValues; return comphelper::containerToSequence(m_aValues);
} }
#ifdef DEBUG_WRITERFILTER #ifdef DEBUG_WRITERFILTER
......
...@@ -105,7 +105,7 @@ public: ...@@ -105,7 +105,7 @@ public:
class PropertyMap class PropertyMap
{ {
/// Cache the property values for the GetPropertyValues() call(s). /// Cache the property values for the GetPropertyValues() call(s).
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aValues; std::vector< ::com::sun::star::beans::PropertyValue > m_aValues;
//marks context as footnote context - ::text( ) events contain either the footnote character or can be ignored //marks context as footnote context - ::text( ) events contain either the footnote character or can be ignored
//depending on sprmCSymbol //depending on sprmCSymbol
...@@ -123,8 +123,8 @@ class PropertyMap ...@@ -123,8 +123,8 @@ class PropertyMap
protected: protected:
void Invalidate() void Invalidate()
{ {
if(m_aValues.getLength()) if(m_aValues.size())
m_aValues.realloc( 0 ); m_aValues.clear();
} }
public: public:
...@@ -136,7 +136,7 @@ public: ...@@ -136,7 +136,7 @@ public:
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > GetPropertyValues(bool bCharGrabBag = true); ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > GetPropertyValues(bool bCharGrabBag = true);
//Sequence: Grab Bags: The CHAR_GRAB_BAG has Name "CharInteropGrabBag" and the PARA_GRAB_BAG has Name "ParaInteropGrabBag" //Sequence: Grab Bags: The CHAR_GRAB_BAG has Name "CharInteropGrabBag" and the PARA_GRAB_BAG has Name "ParaInteropGrabBag"
// the contained properties are their Value. // the contained properties are their Value.
bool hasEmptyPropertyValues() const {return !m_aValues.getLength();} bool hasEmptyPropertyValues() const {return m_aValues.empty();}
//Add property, optionally overwriting existing attributes //Add property, optionally overwriting existing attributes
void Insert( PropertyIds eId, const ::com::sun::star::uno::Any& rAny, bool bOverwrite = true, GrabBagType i_GrabBagType = NO_GRAB_BAG ); void Insert( PropertyIds eId, const ::com::sun::star::uno::Any& rAny, bool bOverwrite = true, GrabBagType i_GrabBagType = NO_GRAB_BAG );
......
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