summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-04-27 09:44:15 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-04-29 08:30:17 +0200
commit8647288180806f8515bf2548db7280cbc657eaf3 (patch)
treecde7f2e1547373f816ae583926fac2d6ddc4a5e6
parentbeacd77aa985ed90532cd5fdd7b56314c0a7b0eb (diff)
optimise comphelper::AttributeList a little
Change-Id: I48cb0a1b5dfcf6471c1cdf9d79445281f9f33020 Reviewed-on: https://gerrit.libreoffice.org/71463 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--comphelper/source/xml/attributelist.cxx70
-rw-r--r--include/comphelper/attributelist.hxx40
2 files changed, 37 insertions, 73 deletions
diff --git a/comphelper/source/xml/attributelist.cxx b/comphelper/source/xml/attributelist.cxx
index 6c1578defd8f..fa918d01da29 100644
--- a/comphelper/source/xml/attributelist.cxx
+++ b/comphelper/source/xml/attributelist.cxx
@@ -27,57 +27,9 @@ using namespace com::sun::star;
namespace comphelper {
-struct TagAttribute_Impl
-{
- TagAttribute_Impl( const OUString &aName, const OUString &aType,
- const OUString &aValue )
- {
- sName = aName;
- sType = aType;
- sValue = aValue;
- }
-
- OUString sName;
- OUString sType;
- OUString sValue;
-};
-
-struct AttributeList_Impl
-{
- AttributeList_Impl()
- {
- // performance improvement during adding
- vecAttribute.reserve(20);
- }
- std::vector<struct TagAttribute_Impl> vecAttribute;
-};
-
-sal_Int16 SAL_CALL AttributeList::getLength()
-{
- return static_cast<sal_Int16>(m_pImpl->vecAttribute.size());
-}
-
-OUString SAL_CALL AttributeList::getNameByIndex(sal_Int16 i)
-{
- return ( i < static_cast < sal_Int16 > (m_pImpl->vecAttribute.size()) ) ? m_pImpl->vecAttribute[i].sName : OUString();
-}
-
-OUString SAL_CALL AttributeList::getTypeByIndex(sal_Int16 i)
-{
- if( i < static_cast < sal_Int16 > (m_pImpl->vecAttribute.size() ) ) {
- return m_pImpl->vecAttribute[i].sType;
- }
- return OUString();
-}
-
-OUString SAL_CALL AttributeList::getValueByIndex(sal_Int16 i)
-{
- return ( i < static_cast < sal_Int16 > (m_pImpl->vecAttribute.size() ) ) ? m_pImpl->vecAttribute[i].sValue : OUString();
-}
-
OUString SAL_CALL AttributeList::getTypeByName( const OUString& sName )
{
- for (auto const& attribute : m_pImpl->vecAttribute)
+ for (auto const& attribute : mAttributes)
{
if( attribute.sName == sName ) {
return attribute.sType;
@@ -88,7 +40,7 @@ OUString SAL_CALL AttributeList::getTypeByName( const OUString& sName )
OUString SAL_CALL AttributeList::getValueByName(const OUString& sName)
{
- for (auto const& attribute : m_pImpl->vecAttribute)
+ for (auto const& attribute : mAttributes)
{
if( attribute.sName == sName ) {
return attribute.sValue;
@@ -98,34 +50,22 @@ OUString SAL_CALL AttributeList::getValueByName(const OUString& sName)
}
AttributeList::AttributeList()
- : m_pImpl(new AttributeList_Impl)
{
+ // performance improvement during adding
+ mAttributes.reserve(20);
}
AttributeList::AttributeList(const AttributeList &r)
: cppu::WeakImplHelper<XAttributeList, XCloneable>(r)
- , m_pImpl(new AttributeList_Impl)
{
- *m_pImpl = *(r.m_pImpl);
+ mAttributes = r.mAttributes;
}
AttributeList::~AttributeList()
{
}
-void AttributeList::AddAttribute(const OUString &sName,
- const OUString &sType, const OUString &sValue)
-{
- m_pImpl->vecAttribute.emplace_back(sName, sType, sValue );
-}
-
-void AttributeList::Clear()
-{
- m_pImpl->vecAttribute.clear();
-}
-
css::uno::Reference< css::util::XCloneable > AttributeList::createClone()
-
{
AttributeList *p = new AttributeList( *this );
return css::uno::Reference< css::util::XCloneable > ( static_cast<css::util::XCloneable *>(p) );
diff --git a/include/comphelper/attributelist.hxx b/include/comphelper/attributelist.hxx
index 91635a412765..8d9248fd57c2 100644
--- a/include/comphelper/attributelist.hxx
+++ b/include/comphelper/attributelist.hxx
@@ -23,6 +23,7 @@
#include <sal/config.h>
#include <memory>
+#include <vector>
#include <com/sun/star/util/XCloneable.hpp>
#include <com/sun/star/xml/sax/XAttributeList.hpp>
@@ -32,12 +33,17 @@
namespace comphelper
{
-struct AttributeList_Impl;
+struct TagAttribute
+{
+ OUString sName;
+ OUString sType;
+ OUString sValue;
+};
class COMPHELPER_DLLPUBLIC AttributeList :
public ::cppu::WeakImplHelper<css::xml::sax::XAttributeList, css::util::XCloneable>
{
- std::unique_ptr<AttributeList_Impl> m_pImpl;
+ std::vector<TagAttribute> mAttributes;
public:
AttributeList();
AttributeList(const AttributeList &r);
@@ -45,15 +51,33 @@ public:
virtual ~AttributeList() override;
// methods that are not contained in any interface
- void AddAttribute(const OUString &sName , const OUString &sType , const OUString &sValue);
- void Clear();
+ void AddAttribute(const OUString &sName , const OUString &sType , const OUString &sValue)
+ {
+ mAttributes.push_back({sName, sType, sValue});
+ }
+ void Clear()
+ {
+ mAttributes.clear();
+ }
// css::xml::sax::XAttributeList
- virtual sal_Int16 SAL_CALL getLength() override;
- virtual OUString SAL_CALL getNameByIndex(sal_Int16 i) override;
- virtual OUString SAL_CALL getTypeByIndex(sal_Int16 i) override;
+ virtual sal_Int16 SAL_CALL getLength() override
+ {
+ return static_cast<sal_Int16>(mAttributes.size());
+ }
+ virtual OUString SAL_CALL getNameByIndex(sal_Int16 i) override
+ {
+ return mAttributes[i].sName;
+ }
+ virtual OUString SAL_CALL getTypeByIndex(sal_Int16 i) override
+ {
+ return mAttributes[i].sType;
+ }
virtual OUString SAL_CALL getTypeByName(const OUString& aName) override;
- virtual OUString SAL_CALL getValueByIndex(sal_Int16 i) override;
+ virtual OUString SAL_CALL getValueByIndex(sal_Int16 i) override
+ {
+ return mAttributes[i].sValue;
+ }
virtual OUString SAL_CALL getValueByName(const OUString& aName) override;
// css::util::XCloneable