summaryrefslogtreecommitdiff
path: root/package
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2021-06-21 10:49:55 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-06-22 15:13:05 +0200
commita1cb4c7665f474c9099c734ad3e6a16c9079a6af (patch)
tree2f093df0ce01e3532931381d978f41935e59c6fa /package
parentbe0a41679fea524e0935dc6617b5e65349812dd1 (diff)
reduce allocation in ZipContentInfo map
This is a small struct, no sense in allocating it separately Change-Id: I709daebbde648a79f175f74c207bdf4871ae6ff1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117604 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'package')
-rw-r--r--package/inc/HashMaps.hxx6
-rw-r--r--package/inc/ZipFile.hxx1
-rw-r--r--package/inc/ZipPackage.hxx1
-rw-r--r--package/inc/ZipPackageFolder.hxx28
-rw-r--r--package/source/zippackage/ContentInfo.hxx60
-rw-r--r--package/source/zippackage/ZipPackage.cxx1
-rw-r--r--package/source/zippackage/ZipPackageEntry.cxx1
-rw-r--r--package/source/zippackage/ZipPackageFolder.cxx51
-rw-r--r--package/source/zippackage/ZipPackageFolderEnumeration.cxx3
-rw-r--r--package/source/zippackage/ZipPackageFolderEnumeration.hxx2
10 files changed, 67 insertions, 87 deletions
diff --git a/package/inc/HashMaps.hxx b/package/inc/HashMaps.hxx
index 46df27962cf9..000afa9e3ba2 100644
--- a/package/inc/HashMaps.hxx
+++ b/package/inc/HashMaps.hxx
@@ -20,11 +20,8 @@
#define INCLUDED_PACKAGE_INC_HASHMAPS_HXX
#include "ZipEntry.hxx"
-#include <rtl/ref.hxx>
#include <unordered_map>
-#include <memory>
-
class ZipPackageFolder;
struct ZipContentInfo;
@@ -32,9 +29,6 @@ typedef std::unordered_map < OUString,
ZipPackageFolder * > FolderHash;
typedef std::unordered_map < OUString,
- std::unique_ptr<ZipContentInfo> > ContentHash;
-
-typedef std::unordered_map < OUString,
ZipEntry > EntryHash;
#endif
diff --git a/package/inc/ZipFile.hxx b/package/inc/ZipFile.hxx
index 221a89a69d76..01a7b562edcc 100644
--- a/package/inc/ZipFile.hxx
+++ b/package/inc/ZipFile.hxx
@@ -28,6 +28,7 @@
#include <comphelper/refcountedmutex.hxx>
#include <package/Inflater.hxx>
+#include <rtl/ref.hxx>
#include "ByteGrabber.hxx"
#include "HashMaps.hxx"
#include "EncryptionData.hxx"
diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx
index ec39666fbbb1..64b94ffb8a72 100644
--- a/package/inc/ZipPackage.hxx
+++ b/package/inc/ZipPackage.hxx
@@ -32,6 +32,7 @@
#include <com/sun/star/xml/crypto/CipherID.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <comphelper/refcountedmutex.hxx>
+#include <rtl/ref.hxx>
#include "HashMaps.hxx"
#include <osl/file.h>
diff --git a/package/inc/ZipPackageFolder.hxx b/package/inc/ZipPackageFolder.hxx
index 96d486fc6e3c..6be8063fe27b 100644
--- a/package/inc/ZipPackageFolder.hxx
+++ b/package/inc/ZipPackageFolder.hxx
@@ -23,15 +23,41 @@
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/beans/StringPair.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
-#include "HashMaps.hxx"
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
#include "ZipPackageEntry.hxx"
#include <cppuhelper/implbase.hxx>
#include <string_view>
+#include <unordered_map>
#include <vector>
class ZipOutputStream;
struct ZipEntry;
+class ZipPackageFolder;
+class ZipPackageStream;
+
+struct ZipContentInfo
+{
+ css::uno::Reference < css::lang::XUnoTunnel > xTunnel;
+ bool bFolder;
+ union
+ {
+ ZipPackageFolder *pFolder;
+ ZipPackageStream *pStream;
+ };
+ ZipContentInfo( ZipPackageStream * pNewStream );
+ ZipContentInfo( ZipPackageFolder * pNewFolder );
+ ZipContentInfo( const ZipContentInfo& );
+ ZipContentInfo( ZipContentInfo&& );
+ ZipContentInfo& operator=( const ZipContentInfo& );
+ ZipContentInfo& operator=( ZipContentInfo&& );
+
+ ~ZipContentInfo();
+};
+
+typedef std::unordered_map < OUString,
+ ZipContentInfo > ContentHash;
class ZipPackageFolder : public cppu::ImplInheritanceHelper
<
diff --git a/package/source/zippackage/ContentInfo.hxx b/package/source/zippackage/ContentInfo.hxx
deleted file mode 100644
index a3e34de1434d..000000000000
--- a/package/source/zippackage/ContentInfo.hxx
+++ /dev/null
@@ -1,60 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-#ifndef INCLUDED_PACKAGE_SOURCE_ZIPPACKAGE_CONTENTINFO_HXX
-#define INCLUDED_PACKAGE_SOURCE_ZIPPACKAGE_CONTENTINFO_HXX
-
-#include <com/sun/star/container/XNameContainer.hpp>
-#include <com/sun/star/lang/XUnoTunnel.hpp>
-#include <ZipPackageFolder.hxx>
-#include <ZipPackageStream.hxx>
-
-struct ZipContentInfo
-{
- css::uno::Reference < css::lang::XUnoTunnel > xTunnel;
- bool bFolder;
- union
- {
- ZipPackageFolder *pFolder;
- ZipPackageStream *pStream;
- };
- ZipContentInfo ( ZipPackageStream * pNewStream )
- : xTunnel ( pNewStream )
- , bFolder ( false )
- , pStream ( pNewStream )
- {
- }
- ZipContentInfo ( ZipPackageFolder * pNewFolder )
- : xTunnel ( pNewFolder )
- , bFolder ( true )
- , pFolder ( pNewFolder )
- {
- }
-
- ~ZipContentInfo()
- {
- if ( bFolder )
- pFolder->clearParent();
- else
- pStream->clearParent();
- }
-};
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx
index 6afba83a49e5..0bf1b331fd5f 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -60,7 +60,6 @@
#include <com/sun/star/xml/crypto/DigestID.hpp>
#include <com/sun/star/xml/crypto/CipherID.hpp>
#include <cppuhelper/implbase.hxx>
-#include "ContentInfo.hxx"
#include <cppuhelper/typeprovider.hxx>
#include <rtl/uri.hxx>
#include <rtl/random.h>
diff --git a/package/source/zippackage/ZipPackageEntry.cxx b/package/source/zippackage/ZipPackageEntry.cxx
index 86b4906711bd..a195596b0672 100644
--- a/package/source/zippackage/ZipPackageEntry.cxx
+++ b/package/source/zippackage/ZipPackageEntry.cxx
@@ -25,7 +25,6 @@
#include <ZipPackageFolder.hxx>
#include <ZipPackageStream.hxx>
-#include "ContentInfo.hxx"
#include <comphelper/storagehelper.hxx>
diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx
index f867b4571b91..3e1deee05592 100644
--- a/package/source/zippackage/ZipPackageFolder.cxx
+++ b/package/source/zippackage/ZipPackageFolder.cxx
@@ -34,7 +34,6 @@
#include <osl/diagnose.h>
#include <sal/log.hxx>
#include <rtl/digest.h>
-#include "ContentInfo.hxx"
#include <com/sun/star/beans/PropertyValue.hpp>
#include <EncryptedDataHeader.hxx>
#include <rtl/instance.hxx>
@@ -83,10 +82,8 @@ bool ZipPackageFolder::LookForUnexpectedODF12Streams( std::u16string_view aPath
{
bool bHasUnexpected = false;
- for (const auto& [rShortName, rxInfo] : maContents)
+ for (const auto& [rShortName, rInfo] : maContents)
{
- const ZipContentInfo &rInfo = *rxInfo;
-
if ( rInfo.bFolder )
{
if ( aPath == u"META-INF/" )
@@ -140,10 +137,8 @@ void ZipPackageFolder::setChildStreamsTypeByExtension( const beans::StringPair&
else
aExt = "." + aPair.First;
- for (const auto& [rShortName, rxInfo] : maContents)
+ for (const auto& [rShortName, rInfo] : maContents)
{
- const ZipContentInfo &rInfo = *rxInfo;
-
if ( rInfo.bFolder )
rInfo.pFolder->setChildStreamsTypeByExtension( aPair );
else
@@ -219,7 +214,7 @@ ZipContentInfo& ZipPackageFolder::doGetByName( const OUString& aName )
ContentHash::iterator aIter = maContents.find ( aName );
if ( aIter == maContents.end())
throw NoSuchElementException(THROW_WHERE );
- return *aIter->second;
+ return aIter->second;
}
uno::Any SAL_CALL ZipPackageFolder::getByName( const OUString& aName )
@@ -314,10 +309,10 @@ void ZipPackageFolder::saveContents(
{
// let the "mimetype" stream in root folder be stored as the first stream if it is zip format
ContentHash::const_iterator aIter = maContents.find ( aMimeTypeStreamName );
- if ( aIter != maContents.end() && !(*aIter).second->bFolder )
+ if ( aIter != maContents.end() && !(*aIter).second.bFolder )
{
bMimeTypeStreamStored = true;
- if( !aIter->second->pStream->saveChild(
+ if( !aIter->second.pStream->saveChild(
rPath + aIter->first, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool ))
{
throw uno::RuntimeException( THROW_WHERE );
@@ -325,10 +320,8 @@ void ZipPackageFolder::saveContents(
}
}
- for (const auto& [rShortName, rxInfo] : maContents)
+ for (const auto& [rShortName, rInfo] : maContents)
{
- const ZipContentInfo &rInfo = *rxInfo;
-
if ( !bMimeTypeStreamStored || rShortName != aMimeTypeStreamName )
{
if (rInfo.bFolder)
@@ -396,9 +389,9 @@ uno::Any SAL_CALL ZipPackageFolder::getPropertyValue( const OUString& PropertyNa
void ZipPackageFolder::doInsertByName ( ZipPackageEntry *pEntry, bool bSetParent )
{
if ( pEntry->IsFolder() )
- maContents[pEntry->getName()] = std::make_unique<ZipContentInfo>(static_cast<ZipPackageFolder*>(pEntry));
+ maContents.emplace(pEntry->getName(), ZipContentInfo(static_cast<ZipPackageFolder*>(pEntry)));
else
- maContents[pEntry->getName()] = std::make_unique<ZipContentInfo>(static_cast<ZipPackageStream*>(pEntry));
+ maContents.emplace(pEntry->getName(), ZipContentInfo(static_cast<ZipPackageStream*>(pEntry)));
if ( bSetParent )
pEntry->setParent ( *this );
}
@@ -418,4 +411,32 @@ sal_Bool SAL_CALL ZipPackageFolder::supportsService( OUString const & rServiceNa
return cppu::supportsService(this, rServiceName);
}
+
+ZipContentInfo::ZipContentInfo ( ZipPackageStream * pNewStream )
+: xTunnel ( pNewStream )
+, bFolder ( false )
+, pStream ( pNewStream )
+{
+}
+
+ZipContentInfo::ZipContentInfo ( ZipPackageFolder * pNewFolder )
+: xTunnel ( pNewFolder )
+, bFolder ( true )
+, pFolder ( pNewFolder )
+{
+}
+
+ZipContentInfo::ZipContentInfo( const ZipContentInfo& ) = default;
+ZipContentInfo::ZipContentInfo( ZipContentInfo&& ) = default;
+ZipContentInfo& ZipContentInfo::operator=( const ZipContentInfo& ) = default;
+ZipContentInfo& ZipContentInfo::operator=( ZipContentInfo&& ) = default;
+
+ZipContentInfo::~ZipContentInfo()
+{
+ if ( bFolder )
+ pFolder->clearParent();
+ else
+ pStream->clearParent();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/package/source/zippackage/ZipPackageFolderEnumeration.cxx b/package/source/zippackage/ZipPackageFolderEnumeration.cxx
index 72b4650f24dd..7b08e18909ce 100644
--- a/package/source/zippackage/ZipPackageFolderEnumeration.cxx
+++ b/package/source/zippackage/ZipPackageFolderEnumeration.cxx
@@ -18,7 +18,6 @@
*/
#include "ZipPackageFolderEnumeration.hxx"
-#include "ContentInfo.hxx"
#include <cppuhelper/supportsservice.hxx>
#include <sal/log.hxx>
@@ -47,7 +46,7 @@ uno::Any SAL_CALL ZipPackageFolderEnumeration::nextElement()
uno::Any aAny;
if (aIterator == rContents.end())
throw container::NoSuchElementException(THROW_WHERE);
- aAny <<= (*aIterator).second->xTunnel;
+ aAny <<= (*aIterator).second.xTunnel;
++aIterator;
return aAny;
}
diff --git a/package/source/zippackage/ZipPackageFolderEnumeration.hxx b/package/source/zippackage/ZipPackageFolderEnumeration.hxx
index 5544478cd475..f3b805b2aa76 100644
--- a/package/source/zippackage/ZipPackageFolderEnumeration.hxx
+++ b/package/source/zippackage/ZipPackageFolderEnumeration.hxx
@@ -22,7 +22,7 @@
#include <cppuhelper/implbase.hxx>
#include <com/sun/star/container/XEnumeration.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <HashMaps.hxx>
+#include <ZipPackageFolder.hxx>
class ZipPackageFolderEnumeration final
: public cppu::WeakImplHelper<css::container::XEnumeration, css::lang::XServiceInfo>