diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-21 14:58:14 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-12-22 08:21:12 +0100 |
commit | 05044640531055c86b34f1c6ec8055c8a0ca3df8 (patch) | |
tree | bd5a756138f618ee54f48f3f4df8d07ccd905e67 /comphelper | |
parent | 03fcb4aae62a9403f22ec3671b61555419d02514 (diff) |
use boost::optional for OUString
instead of storing on heap
Change-Id: I4ca2bb58ec4f71b161c9e6081f5e456de54d8153
Reviewed-on: https://gerrit.libreoffice.org/65537
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/source/officeinstdir/officeinstallationdirectories.cxx | 35 | ||||
-rw-r--r-- | comphelper/source/officeinstdir/officeinstallationdirectories.hxx | 5 |
2 files changed, 19 insertions, 21 deletions
diff --git a/comphelper/source/officeinstdir/officeinstallationdirectories.cxx b/comphelper/source/officeinstdir/officeinstallationdirectories.cxx index c6f91ffa7c1b..fae3d7c4f059 100644 --- a/comphelper/source/officeinstdir/officeinstallationdirectories.cxx +++ b/comphelper/source/officeinstdir/officeinstallationdirectories.cxx @@ -99,7 +99,7 @@ OUString SAL_CALL OfficeInstallationDirectories::getOfficeInstallationDirectoryURL() { initDirs(); - return *m_pOfficeBrandDir; + return *m_xOfficeBrandDir; } @@ -108,7 +108,7 @@ OUString SAL_CALL OfficeInstallationDirectories::getOfficeUserDataDirectoryURL() { initDirs(); - return *m_pUserDir; + return *m_xUserDir; } @@ -124,22 +124,22 @@ OfficeInstallationDirectories::makeRelocatableURL( const OUString& URL ) OUString aCanonicalURL( URL ); makeCanonicalFileURL( aCanonicalURL ); - sal_Int32 nIndex = aCanonicalURL.indexOf( *m_pOfficeBrandDir ); + sal_Int32 nIndex = aCanonicalURL.indexOf( *m_xOfficeBrandDir ); if ( nIndex != -1 ) { return aCanonicalURL.replaceAt( nIndex, - m_pOfficeBrandDir->getLength(), + m_xOfficeBrandDir->getLength(), g_aOfficeBrandDirMacro ); } else { - nIndex = aCanonicalURL.indexOf( *m_pUserDir ); + nIndex = aCanonicalURL.indexOf( *m_xUserDir ); if ( nIndex != -1 ) { return aCanonicalURL.replaceAt( nIndex, - m_pUserDir->getLength(), + m_xUserDir->getLength(), g_aUserDirMacro ); } } @@ -162,7 +162,7 @@ OfficeInstallationDirectories::makeAbsoluteURL( const OUString& URL ) return URL.replaceAt( nIndex, g_aOfficeBrandDirMacro.getLength(), - *m_pOfficeBrandDir ); + *m_xOfficeBrandDir ); } else { @@ -174,7 +174,7 @@ OfficeInstallationDirectories::makeAbsoluteURL( const OUString& URL ) return URL.replaceAt( nIndex, g_aUserDirMacro.getLength(), - *m_pUserDir ); + *m_xUserDir ); } } } @@ -208,31 +208,28 @@ OfficeInstallationDirectories::getSupportedServiceNames() void OfficeInstallationDirectories::initDirs() { - if ( m_pOfficeBrandDir == nullptr ) + if ( !m_xOfficeBrandDir) { osl::MutexGuard aGuard( m_aMutex ); - if ( m_pOfficeBrandDir == nullptr ) + if ( !m_xOfficeBrandDir ) { - m_pOfficeBrandDir.reset( new OUString ); - m_pUserDir.reset( new OUString ); - uno::Reference< util::XMacroExpander > xExpander = util::theMacroExpander::get(m_xCtx); - *m_pOfficeBrandDir = xExpander->expandMacros( "$BRAND_BASE_DIR" ); + m_xOfficeBrandDir = xExpander->expandMacros( "$BRAND_BASE_DIR" ); - OSL_ENSURE( !m_pOfficeBrandDir->isEmpty(), + OSL_ENSURE( !m_xOfficeBrandDir->isEmpty(), "Unable to obtain office brand installation directory!" ); - makeCanonicalFileURL( *m_pOfficeBrandDir ); + makeCanonicalFileURL( *m_xOfficeBrandDir ); - *m_pUserDir = + m_xUserDir = xExpander->expandMacros( "${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( "bootstrap" ) ":UserInstallation}" ); - OSL_ENSURE( !m_pUserDir->isEmpty(), + OSL_ENSURE( !m_xUserDir->isEmpty(), "Unable to obtain office user data directory!" ); - makeCanonicalFileURL( *m_pUserDir ); + makeCanonicalFileURL( *m_xUserDir ); } } } diff --git a/comphelper/source/officeinstdir/officeinstallationdirectories.hxx b/comphelper/source/officeinstdir/officeinstallationdirectories.hxx index bfcde8d72876..e4fb6dd6a0f9 100644 --- a/comphelper/source/officeinstdir/officeinstallationdirectories.hxx +++ b/comphelper/source/officeinstdir/officeinstallationdirectories.hxx @@ -27,6 +27,7 @@ #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/util/XOfficeInstallationDirectories.hpp> #include <memory> +#include <boost/optional.hpp> namespace comphelper { @@ -70,8 +71,8 @@ private: void initDirs(); css::uno::Reference< css::uno::XComponentContext > m_xCtx; - std::unique_ptr<OUString> m_pOfficeBrandDir; - std::unique_ptr<OUString> m_pUserDir; + boost::optional<OUString> m_xOfficeBrandDir; + boost::optional<OUString> m_xUserDir; }; } // namespace comphelper |