Kaydet (Commit) 86472881 authored tarafından Noel Grandin's avatar Noel Grandin

optimise comphelper::AttributeList a little

Change-Id: I48cb0a1b5dfcf6471c1cdf9d79445281f9f33020
Reviewed-on: https://gerrit.libreoffice.org/71463
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst beacd77a
......@@ -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) );
......
......@@ -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
......
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