diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2016-04-03 16:40:26 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2016-04-05 06:25:12 +0000 |
commit | 55d146b732bf30f6a83a962b4394df8f2563a4b7 (patch) | |
tree | e2b5c29fb24344c21b9aa53ab9887391b7a4db74 /sw | |
parent | ac19ed0fed3197af2ed3f07e00185befcb90a8fe (diff) |
sequence->vector in sw
Change-Id: I042fd1ce0fd9a55ebe4372599fede97990712528
Reviewed-on: https://gerrit.libreoffice.org/23758
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/access/accpara.cxx | 38 | ||||
-rw-r--r-- | sw/source/core/access/accpara.hxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unofield.cxx | 37 |
3 files changed, 24 insertions, 53 deletions
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx index c8256388fd6c..b30442fe73d1 100644 --- a/sw/source/core/access/accpara.cxx +++ b/sw/source/core/access/accpara.cxx @@ -1641,8 +1641,7 @@ uno::Sequence<PropertyValue> SwAccessibleParagraph::getCharacterAttributes( _getRunAttributesImpl( nIndex, aNames, aRunAttrSeq ); // merge default and run attributes - uno::Sequence< PropertyValue > aValues( aDefAttrSeq.size() ); - PropertyValue* pValues = aValues.getArray(); + std::vector< PropertyValue > aValues( aDefAttrSeq.size() ); sal_Int32 i = 0; for ( tAccParaPropValMap::const_iterator aDefIter = aDefAttrSeq.begin(); aDefIter != aDefAttrSeq.end(); @@ -1652,11 +1651,11 @@ uno::Sequence<PropertyValue> SwAccessibleParagraph::getCharacterAttributes( aRunAttrSeq.find( aDefIter->first ); if ( aRunIter != aRunAttrSeq.end() ) { - pValues[i] = aRunIter->second; + aValues[i] = aRunIter->second; } else { - pValues[i] = aDefIter->second; + aValues[i] = aDefIter->second; } ++i; } @@ -1669,29 +1668,25 @@ uno::Sequence<PropertyValue> SwAccessibleParagraph::getCharacterAttributes( tAccParaPropValMap aSupplementalAttrSeq; _getSupplementalAttributesImpl( nIndex, aSupplementalNames, aSupplementalAttrSeq ); - aValues.realloc( aValues.getLength() + aSupplementalAttrSeq.size() ); - pValues = aValues.getArray(); + aValues.resize( aValues.size() + aSupplementalAttrSeq.size() ); for ( tAccParaPropValMap::const_iterator aSupplementalIter = aSupplementalAttrSeq.begin(); aSupplementalIter != aSupplementalAttrSeq.end(); ++aSupplementalIter ) { - pValues[i] = aSupplementalIter->second; + aValues[i] = aSupplementalIter->second; ++i; } _correctValues( nIndex, aValues ); - aValues.realloc( aValues.getLength() + 1 ); - - pValues = aValues.getArray(); + aValues.resize( aValues.size() + 1 ); OUString strTypeName = GetFieldTypeNameAtIndex(nIndex); if (!strTypeName.isEmpty()) { - aValues.realloc( aValues.getLength() + 1 ); - pValues = aValues.getArray(); - PropertyValue& rValueFT = pValues[aValues.getLength() - 1]; + aValues.resize( aValues.size() + 1 ); + PropertyValue& rValueFT = aValues[aValues.size() - 1]; rValueFT.Name = "FieldType"; rValueFT.Value <<= strTypeName.toAsciiLowerCase(); rValueFT.Handle = -1; @@ -1700,24 +1695,23 @@ uno::Sequence<PropertyValue> SwAccessibleParagraph::getCharacterAttributes( //sort property values // build sorted index array - sal_Int32 nLength = aValues.getLength(); - const PropertyValue* pPairs = aValues.getConstArray(); + sal_Int32 nLength = aValues.size(); sal_Int32* pIndices = new sal_Int32[nLength]; for( i = 0; i < nLength; i++ ) pIndices[i] = i; - sort( &pIndices[0], &pIndices[nLength], IndexCompare(pPairs) ); + sort( &pIndices[0], &pIndices[nLength], IndexCompare(aValues.data()) ); // create sorted sequences according to index array uno::Sequence<PropertyValue> aNewValues( nLength ); PropertyValue* pNewValues = aNewValues.getArray(); for( i = 0; i < nLength; i++ ) { - pNewValues[i] = pPairs[pIndices[i]]; + pNewValues[i] = aValues[pIndices[i]]; } delete[] pIndices; return aNewValues; } - return aValues; + return comphelper::containerToSequence(aValues); } static void SetPutRecursive(SfxItemSet &targetSet, const SfxItemSet &sourceSet) @@ -2144,7 +2138,7 @@ void SwAccessibleParagraph::_getSupplementalAttributesImpl( } void SwAccessibleParagraph::_correctValues( const sal_Int32 nIndex, - uno::Sequence< PropertyValue >& rValues) + std::vector< PropertyValue >& rValues) { PropertyValue ChangeAttr, ChangeAttrColor; @@ -2209,14 +2203,12 @@ void SwAccessibleParagraph::_correctValues( const sal_Int32 nIndex, } } - PropertyValue* pValues = rValues.getArray(); - const SwTextNode* pTextNode( GetTextNode() ); - sal_Int32 nValues = rValues.getLength(); + sal_Int32 nValues = rValues.size(); for (sal_Int32 i = 0; i < nValues; ++i) { - PropertyValue& rValue = pValues[i]; + PropertyValue& rValue = rValues[i]; if (rValue.Name == ChangeAttr.Name ) { diff --git a/sw/source/core/access/accpara.hxx b/sw/source/core/access/accpara.hxx index 9051f2a7c187..bceb0b186df5 100644 --- a/sw/source/core/access/accpara.hxx +++ b/sw/source/core/access/accpara.hxx @@ -157,7 +157,7 @@ class SwAccessibleParagraph : void _correctValues( const sal_Int32 nIndex, - css::uno::Sequence< css::beans::PropertyValue >& rValues ); + std::vector< css::beans::PropertyValue >& rValues ); public: SwTOXSortTabBase* GetTOXSortTabBase(); diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index 55e3d98cf70c..b77704599dbe 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -2960,7 +2960,7 @@ class SwXFieldEnumeration::Impl public: SwDoc * m_pDoc; - uno::Sequence< uno::Reference<text::XTextField> > m_Items; + std::vector< uno::Reference<text::XTextField> > m_Items; sal_Int32 m_nNextIndex; ///< index of next element to be returned explicit Impl(SwDoc & rDoc) @@ -2997,10 +2997,7 @@ SwXFieldEnumeration::SwXFieldEnumeration(SwDoc & rDoc) : m_pImpl(new Impl(rDoc)) { // build sequence - sal_Int32 nSize = 32; - m_pImpl->m_Items.realloc( nSize ); - uno::Reference< text::XTextField > *pItems = m_pImpl->m_Items.getArray(); - sal_Int32 nFillPos = 0; + m_pImpl->m_Items.clear(); const SwFieldTypes* pFieldTypes = m_pImpl->m_pDoc->getIDocumentFieldsAccess().GetFieldTypes(); const size_t nCount = pFieldTypes->size(); @@ -3017,16 +3014,9 @@ SwXFieldEnumeration::SwXFieldEnumeration(SwDoc & rDoc) bool bSkip = !pTextField || !pTextField->GetpTextNode()->GetNodes().IsDocNodes(); if (!bSkip) - pItems[ nFillPos++ ] = SwXTextField::CreateXTextField( - m_pImpl->m_pDoc, pCurFieldFormat); + m_pImpl->m_Items.push_back( SwXTextField::CreateXTextField( + m_pImpl->m_pDoc, pCurFieldFormat)); pCurFieldFormat = aIter.Next(); - - // enlarge sequence if necessary - if (m_pImpl->m_Items.getLength() == nFillPos) - { - m_pImpl->m_Items.realloc( 2 * m_pImpl->m_Items.getLength() ); - pItems = m_pImpl->m_Items.getArray(); - } } } // now handle meta-fields, which are not SwFields @@ -3034,19 +3024,8 @@ SwXFieldEnumeration::SwXFieldEnumeration(SwDoc & rDoc) m_pImpl->m_pDoc->GetMetaFieldManager().getMetaFields() ); for (size_t i = 0; i < MetaFields.size(); ++i) { - pItems[ nFillPos ] = MetaFields[i]; - nFillPos++; - - //FIXME UGLY - // enlarge sequence if necessary - if (m_pImpl->m_Items.getLength() == nFillPos) - { - m_pImpl->m_Items.realloc( 2 * m_pImpl->m_Items.getLength() ); - pItems = m_pImpl->m_Items.getArray(); - } + m_pImpl->m_Items.push_back( MetaFields[i] ); } - // resize sequence to actual used size - m_pImpl->m_Items.realloc( nFillPos ); } SwXFieldEnumeration::~SwXFieldEnumeration() @@ -3058,7 +3037,7 @@ throw (uno::RuntimeException, std::exception) { SolarMutexGuard aGuard; - return m_pImpl->m_nNextIndex < m_pImpl->m_Items.getLength(); + return m_pImpl->m_nNextIndex < (sal_Int32)m_pImpl->m_Items.size(); } uno::Any SAL_CALL SwXFieldEnumeration::nextElement() @@ -3067,7 +3046,7 @@ throw (container::NoSuchElementException, lang::WrappedTargetException, { SolarMutexGuard aGuard; - if (!(m_pImpl->m_nNextIndex < m_pImpl->m_Items.getLength())) + if (!(m_pImpl->m_nNextIndex < (sal_Int32)m_pImpl->m_Items.size())) throw container::NoSuchElementException( "SwXFieldEnumeration::nextElement", css::uno::Reference<css::uno::XInterface>()); @@ -3077,7 +3056,7 @@ throw (container::NoSuchElementException, lang::WrappedTargetException, (void)pItems; #endif uno::Reference< text::XTextField > &rxField = - m_pImpl->m_Items.getArray()[ m_pImpl->m_nNextIndex++ ]; + m_pImpl->m_Items[ m_pImpl->m_nNextIndex++ ]; uno::Any aRet; aRet <<= rxField; rxField = nullptr; // free memory for item that is not longer used |