diff options
author | Noel Grandin <noel@peralex.com> | 2021-06-21 10:49:55 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-06-22 15:13:05 +0200 |
commit | a1cb4c7665f474c9099c734ad3e6a16c9079a6af (patch) | |
tree | 2f093df0ce01e3532931381d978f41935e59c6fa /package/source/zippackage | |
parent | be0a41679fea524e0935dc6617b5e65349812dd1 (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/source/zippackage')
-rw-r--r-- | package/source/zippackage/ContentInfo.hxx | 60 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 1 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageEntry.cxx | 1 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageFolder.cxx | 51 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageFolderEnumeration.cxx | 3 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackageFolderEnumeration.hxx | 2 |
6 files changed, 38 insertions, 80 deletions
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> |