[Libreoffice-commits] core.git: cppuhelper/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Tue Dec 24 10:39:52 UTC 2019


 cppuhelper/source/servicemanager.cxx |  130 +++++++++++++++++------------------
 cppuhelper/source/servicemanager.hxx |   26 ++-----
 2 files changed, 76 insertions(+), 80 deletions(-)

New commits:
commit fc11bce4917aae7e8324f2c721ce50a88d231b0c
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Tue Dec 24 08:51:19 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Dec 24 11:38:51 2019 +0100

    ImplementationInfo can be inlined
    
    no need to hold by shared_ptr, it is never shared
    
    Change-Id: I4818c08e4beab57d777e90d181d92a3edddffbf5
    Reviewed-on: https://gerrit.libreoffice.org/85772
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx
index b4c2503db1a1..c9a21ba1a557 100644
--- a/cppuhelper/source/servicemanager.cxx
+++ b/cppuhelper/source/servicemanager.cxx
@@ -391,13 +391,13 @@ void Parser::handleImplementation() {
 
 void Parser::handleService() {
     OUString name(getNameAttribute());
-    implementation_->info->services.push_back(name);
+    implementation_->info.services.push_back(name);
     data_->services[name].push_back(implementation_);
 }
 
 void Parser::handleSingleton() {
     OUString name(getNameAttribute());
-    implementation_->info->singletons.push_back(name);
+    implementation_->info.singletons.push_back(name);
     data_->singletons[name].push_back(implementation_);
 }
 
@@ -614,7 +614,7 @@ OUString ImplementationWrapper::getImplementationName()
 {
     std::shared_ptr< cppuhelper::ServiceManager::Data::Implementation > impl = implementation_.lock();
     assert(impl);
-    return impl->info->name;
+    return impl->info.name;
 }
 
 sal_Bool ImplementationWrapper::supportsService(OUString const & ServiceName)
@@ -627,15 +627,15 @@ ImplementationWrapper::getSupportedServiceNames()
 {
     std::shared_ptr< cppuhelper::ServiceManager::Data::Implementation > impl = implementation_.lock();
     assert(impl);
-    if (impl->info->services.size()
+    if (impl->info.services.size()
         > static_cast< sal_uInt32 >(SAL_MAX_INT32))
     {
         throw css::uno::RuntimeException(
-            ("Implementation " + impl->info->name
+            ("Implementation " + impl->info.name
              + " supports too many services"),
             static_cast< cppu::OWeakObject * >(this));
     }
-    return comphelper::containerToSequence(impl->info->services);
+    return comphelper::containerToSequence(impl->info.services);
 }
 
 }
@@ -703,7 +703,7 @@ void cppuhelper::ServiceManager::Data::Implementation::updateDisposeSingleton(
         osl::MutexGuard g(mutex);
         disposeSingleton.clear();
         dispose = false;
-    } else if (!info->singletons.empty()) {
+    } else if (!info.singletons.empty()) {
         css::uno::Reference<css::lang::XComponent> comp(
             instance, css::uno::UNO_QUERY);
         if (comp.is()) {
@@ -725,7 +725,7 @@ void cppuhelper::ServiceManager::addSingletonContextEntries(
         assert(rImpls[0].get() != nullptr);
         SAL_INFO_IF(
             rImpls.size() > 1, "cppuhelper",
-            "Arbitrarily choosing " << rImpls[0]->info->name
+            "Arbitrarily choosing " << rImpls[0]->info.name
                 << " among multiple implementations for " << rName);
         entries->push_back(
             cppu::ContextEntry_Init(
@@ -750,45 +750,45 @@ void cppuhelper::ServiceManager::loadImplementation(
     }
     OUString uri;
     try {
-        uri = cppu::bootstrap_expandUri(implementation->info->uri);
+        uri = cppu::bootstrap_expandUri(implementation->info.uri);
     } catch (css::lang::IllegalArgumentException & e) {
         throw css::uno::DeploymentException(
-            "Cannot expand URI" + implementation->info->uri + ": " + e.Message,
+            "Cannot expand URI" + implementation->info.uri + ": " + e.Message,
             static_cast< cppu::OWeakObject * >(this));
     }
     cppuhelper::WrapperConstructorFn ctor;
     css::uno::Reference< css::uno::XInterface > f0;
     // Special handling of SharedLibrary loader, with support for environment,
     // constructor, and prefix arguments:
-    if (!implementation->info->alienContext.is()
-        && implementation->info->loader == "com.sun.star.loader.SharedLibrary")
+    if (!implementation->info.alienContext.is()
+        && implementation->info.loader == "com.sun.star.loader.SharedLibrary")
     {
         cppuhelper::detail::loadSharedLibComponentFactory(
-            uri, implementation->info->environment,
-            implementation->info->prefix, implementation->info->name,
-            implementation->info->constructor, this, &ctor, &f0);
+            uri, implementation->info.environment,
+            implementation->info.prefix, implementation->info.name,
+            implementation->info.constructor, this, &ctor, &f0);
         if (ctor) {
-            assert(!implementation->info->environment.isEmpty());
+            assert(!implementation->info.environment.isEmpty());
         }
     } else {
         SAL_WARN_IF(
-            !implementation->info->environment.isEmpty(), "cppuhelper",
-            "Loader " << implementation->info->loader
+            !implementation->info.environment.isEmpty(), "cppuhelper",
+            "Loader " << implementation->info.loader
                 << " and non-empty environment "
-                << implementation->info->environment);
+                << implementation->info.environment);
         SAL_WARN_IF(
-            !implementation->info->prefix.isEmpty(), "cppuhelper",
-            "Loader " << implementation->info->loader
+            !implementation->info.prefix.isEmpty(), "cppuhelper",
+            "Loader " << implementation->info.loader
                 << " and non-empty constructor "
-                << implementation->info->constructor);
+                << implementation->info.constructor);
         SAL_WARN_IF(
-            !implementation->info->prefix.isEmpty(), "cppuhelper",
-            "Loader " << implementation->info->loader
-                << " and non-empty prefix " << implementation->info->prefix);
+            !implementation->info.prefix.isEmpty(), "cppuhelper",
+            "Loader " << implementation->info.loader
+                << " and non-empty prefix " << implementation->info.prefix);
         css::uno::Reference< css::uno::XComponentContext > ctxt;
         css::uno::Reference< css::lang::XMultiComponentFactory > smgr;
-        if (implementation->info->alienContext.is()) {
-            ctxt = implementation->info->alienContext;
+        if (implementation->info.alienContext.is()) {
+            ctxt = implementation->info.alienContext;
             smgr.set(ctxt->getServiceManager(), css::uno::UNO_SET_THROW);
         } else {
             assert(context.is());
@@ -796,10 +796,10 @@ void cppuhelper::ServiceManager::loadImplementation(
             smgr = this;
         }
         css::uno::Reference< css::loader::XImplementationLoader > loader(
-            smgr->createInstanceWithContext(implementation->info->loader, ctxt),
+            smgr->createInstanceWithContext(implementation->info.loader, ctxt),
             css::uno::UNO_QUERY_THROW);
         f0 = loader->activate(
-            implementation->info->name, OUString(), uri,
+            implementation->info.name, OUString(), uri,
             css::uno::Reference< css::registry::XRegistryKey >());
     }
     css::uno::Reference<css::lang::XSingleComponentFactory> f1;
@@ -810,7 +810,7 @@ void cppuhelper::ServiceManager::loadImplementation(
             f2.set(f0, css::uno::UNO_QUERY);
             if (!f2.is()) {
                 throw css::uno::DeploymentException(
-                    ("Implementation " + implementation->info->name
+                    ("Implementation " + implementation->info.name
                      + " does not provide a constructor or factory"),
                     static_cast< cppu::OWeakObject * >(this));
             }
@@ -839,7 +839,7 @@ void cppuhelper::ServiceManager::disposing() {
         for (const auto& rEntry : data_.namedImplementations)
         {
             assert(rEntry.second.get() != nullptr);
-            if (!rEntry.second->info->singletons.empty()) {
+            if (!rEntry.second->info.singletons.empty()) {
                 osl::MutexGuard g2(rEntry.second->mutex);
                 if (rEntry.second->disposeSingleton.is()) {
                     sngls.push_back(rEntry.second->disposeSingleton);
@@ -849,7 +849,7 @@ void cppuhelper::ServiceManager::disposing() {
         for (const auto& rEntry : data_.dynamicImplementations)
         {
             assert(rEntry.second.get() != nullptr);
-            if (!rEntry.second->info->singletons.empty()) {
+            if (!rEntry.second->info.singletons.empty()) {
                 osl::MutexGuard g2(rEntry.second->mutex);
                 if (rEntry.second->disposeSingleton.is()) {
                     sngls.push_back(rEntry.second->disposeSingleton);
@@ -1402,14 +1402,14 @@ bool cppuhelper::ServiceManager::readLegacyRdbFile(OUString const & uri) {
                 uri + ": duplicate <implementation name=\"" + name + "\">");
         }
         readLegacyRdbStrings(
-            uri, implKey, "UNO/SERVICES", &impl->info->services);
-        for (const auto& rService : impl->info->services)
+            uri, implKey, "UNO/SERVICES", &impl->info.services);
+        for (const auto& rService : impl->info.services)
         {
             data_.services[rService].push_back(impl);
         }
         readLegacyRdbStrings(
-            uri, implKey, "UNO/SINGLETONS", &impl->info->singletons);
-        for (const auto& rSingleton : impl->info->singletons)
+            uri, implKey, "UNO/SINGLETONS", &impl->info.singletons);
+        for (const auto& rSingleton : impl->info.singletons)
         {
             data_.singletons[rSingleton].push_back(impl);
         }
@@ -1530,7 +1530,7 @@ void cppuhelper::ServiceManager::insertLegacyFactory(
     css::uno::Sequence< OUString > services(
         factoryInfo->getSupportedServiceNames());
     for (sal_Int32 i = 0; i != services.getLength(); ++i) {
-        impl->info->services.push_back(services[i]);
+        impl->info.services.push_back(services[i]);
         extra.services[services[i]].push_back(impl);
     }
     if (insertExtraData(extra) && comp.is()) {
@@ -1589,15 +1589,15 @@ bool cppuhelper::ServiceManager::insertExtraData(Data const & extra) {
             assert(rImpls[0].get() != nullptr);
             SAL_INFO_IF(
                 rImpls.size() > 1, "cppuhelper",
-                "Arbitrarily choosing " << rImpls[0]->info->name
+                "Arbitrarily choosing " << rImpls[0]->info.name
                     << " among multiple implementations for singleton "
                     << rName);
             try {
                 cont->insertByName(
-                    name + "/service", css::uno::Any(rImpls[0]->info->name));
+                    name + "/service", css::uno::Any(rImpls[0]->info.name));
             } catch (css::container::ElementExistException &) {
                 cont->replaceByName(
-                    name + "/service", css::uno::Any(rImpls[0]->info->name));
+                    name + "/service", css::uno::Any(rImpls[0]->info.name));
             }
             try {
                 cont->insertByName(name, css::uno::Any());
@@ -1626,14 +1626,14 @@ void cppuhelper::ServiceManager::removeRdbFiles(
                  j != data_.namedImplementations.end();)
             {
                 assert(j->second.get() != nullptr);
-                if (j->second->info->rdbFile == rUri) {
+                if (j->second->info.rdbFile == rUri) {
                     clear.push_back(j->second);
                     //TODO: The below leaves data_ in an inconsistent state upon
                     // exceptions:
                     removeFromImplementationMap(
-                        &data_.services, j->second->info->services, j->second);
+                        &data_.services, j->second->info.services, j->second);
                     removeFromImplementationMap(
-                        &data_.singletons, j->second->info->singletons,
+                        &data_.singletons, j->second->info.singletons,
                         j->second);
                     j = data_.namedImplementations.erase(j);
                 } else {
@@ -1666,11 +1666,11 @@ bool cppuhelper::ServiceManager::removeLegacyFactory(
         }
         //TODO: The below leaves data_ in an inconsistent state upon exceptions:
         removeFromImplementationMap(
-            &data_.services, i->second->info->services, i->second);
+            &data_.services, i->second->info.services, i->second);
         removeFromImplementationMap(
-            &data_.singletons, i->second->info->singletons, i->second);
-        if (!i->second->info->name.isEmpty()) {
-            data_.namedImplementations.erase(i->second->info->name);
+            &data_.singletons, i->second->info.singletons, i->second);
+        if (!i->second->info.name.isEmpty()) {
+            data_.namedImplementations.erase(i->second->info.name);
         }
         data_.dynamicImplementations.erase(i);
     }
@@ -1700,9 +1700,9 @@ void cppuhelper::ServiceManager::removeImplementation(const OUString & name) {
         clear = i->second;
         //TODO: The below leaves data_ in an inconsistent state upon exceptions:
         removeFromImplementationMap(
-            &data_.services, i->second->info->services, i->second);
+            &data_.services, i->second->info.services, i->second);
         removeFromImplementationMap(
-            &data_.singletons, i->second->info->singletons, i->second);
+            &data_.singletons, i->second->info.singletons, i->second);
         auto j = std::find_if(data_.dynamicImplementations.begin(), data_.dynamicImplementations.end(),
             [&i](const Data::DynamicImplementations::value_type& rEntry) { return rEntry.second == i->second; });
         if (j != data_.dynamicImplementations.end())
@@ -1734,7 +1734,7 @@ cppuhelper::ServiceManager::findServiceImplementation(
             assert(!i->second.empty());
             SAL_INFO_IF(
                 i->second.size() > 1, "cppuhelper",
-                "Arbitrarily choosing " << i->second[0]->info->name
+                "Arbitrarily choosing " << i->second[0]->info.name
                     << " among multiple implementations for " << i->first);
             impl = i->second[0];
         }
@@ -1807,14 +1807,14 @@ void cppuhelper::ServiceManager::preloadImplementations() {
     // loop all implementations
     for (const auto& rEntry : data_.namedImplementations)
     {
-        if (rEntry.second->info->loader != "com.sun.star.loader.SharedLibrary" ||
+        if (rEntry.second->info.loader != "com.sun.star.loader.SharedLibrary" ||
             rEntry.second->status == Data::Implementation::STATUS_LOADED)
             continue;
 
         OUString simplified;
         try
         {
-            const OUString &aLibrary = rEntry.second->info->uri;
+            const OUString &aLibrary = rEntry.second->info.uri;
 
             if (aLibrary.isEmpty())
                 continue;
@@ -1848,7 +1848,7 @@ void cppuhelper::ServiceManager::preloadImplementations() {
         catch (css::lang::IllegalArgumentException& aError)
         {
             throw css::uno::DeploymentException(
-                "Cannot expand URI" + rEntry.second->info->uri + ": " + aError.Message,
+                "Cannot expand URI" + rEntry.second->info.uri + ": " + aError.Message,
                 static_cast< cppu::OWeakObject * >(this));
         }
 
@@ -1862,20 +1862,20 @@ void cppuhelper::ServiceManager::preloadImplementations() {
         }
 
         if (aModule.is() &&
-            !rEntry.second->info->environment.isEmpty())
+            !rEntry.second->info.environment.isEmpty())
         {
             OUString aSymFactory;
             oslGenericFunction fpFactory;
             css::uno::Environment aTargetEnv;
             css::uno::Reference<css::uno::XInterface> xFactory;
 
-            if(rEntry.second->info->constructor.isEmpty())
+            if(rEntry.second->info.constructor.isEmpty())
             {
                 // expand full name component factory symbol
-                if (rEntry.second->info->prefix == "direct")
-                    aSymFactory = rEntry.second->info->name.replace('.', '_') + "_" COMPONENT_GETFACTORY;
-                else if (!rEntry.second->info->prefix.isEmpty())
-                    aSymFactory = rEntry.second->info->prefix + "_" COMPONENT_GETFACTORY;
+                if (rEntry.second->info.prefix == "direct")
+                    aSymFactory = rEntry.second->info.name.replace('.', '_') + "_" COMPONENT_GETFACTORY;
+                else if (!rEntry.second->info.prefix.isEmpty())
+                    aSymFactory = rEntry.second->info.prefix + "_" COMPONENT_GETFACTORY;
                 else
                     aSymFactory = COMPONENT_GETFACTORY;
 
@@ -1888,13 +1888,13 @@ void cppuhelper::ServiceManager::preloadImplementations() {
                         css::uno::Reference<css::uno::XInterface>());
                 }
 
-                aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info->environment, rEntry.second->info->name);
+                aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info.environment, rEntry.second->info.name);
                 component_getFactoryFunc fpComponentFactory = reinterpret_cast<component_getFactoryFunc>(fpFactory);
 
                 if (aSourceEnv.get() == aTargetEnv.get())
                 {
                     // invoke function component factory
-                    OString aImpl(OUStringToOString(rEntry.second->info->name, RTL_TEXTENCODING_ASCII_US));
+                    OString aImpl(OUStringToOString(rEntry.second->info.name, RTL_TEXTENCODING_ASCII_US));
                     xFactory.set(css::uno::Reference<css::uno::XInterface>(static_cast<css::uno::XInterface *>(
                         (*fpComponentFactory)(aImpl.getStr(), this, nullptr)), SAL_NO_ACQUIRE));
                 }
@@ -1902,9 +1902,9 @@ void cppuhelper::ServiceManager::preloadImplementations() {
             else
             {
                 // get function symbol component factory
-                aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info->environment, rEntry.second->info->name);
+                aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info.environment, rEntry.second->info.name);
                 fpFactory = (aSourceEnv.get() == aTargetEnv.get()) ?
-                    aModule.getFunctionSymbol(rEntry.second->info->constructor) : nullptr;
+                    aModule.getFunctionSymbol(rEntry.second->info.constructor) : nullptr;
             }
 
             css::uno::Reference<css::lang::XSingleComponentFactory> xSCFactory;
@@ -1919,13 +1919,13 @@ void cppuhelper::ServiceManager::preloadImplementations() {
                     xSSFactory.set(xFactory, css::uno::UNO_QUERY);
                     if (!xSSFactory.is())
                         throw css::uno::DeploymentException(
-                            ("Implementation " + rEntry.second->info->name
+                            ("Implementation " + rEntry.second->info.name
                              + " does not provide a constructor or factory"),
                             static_cast< cppu::OWeakObject * >(this));
                 }
             }
 
-            if (!rEntry.second->info->constructor.isEmpty() && fpFactory)
+            if (!rEntry.second->info.constructor.isEmpty() && fpFactory)
                 rEntry.second->constructor = WrapperConstructorFn(reinterpret_cast<ImplementationConstructorFn *>(fpFactory));
 
             rEntry.second->factory1 = xSCFactory;
diff --git a/cppuhelper/source/servicemanager.hxx b/cppuhelper/source/servicemanager.hxx
index d72b46f0d0a0..b96549ceffce 100644
--- a/cppuhelper/source/servicemanager.hxx
+++ b/cppuhelper/source/servicemanager.hxx
@@ -88,18 +88,15 @@ public:
             explicit ImplementationInfo(OUString const & theName):
                 name(theName) {}
 
-            ImplementationInfo(const ImplementationInfo&) = delete;
-            const ImplementationInfo& operator=(const ImplementationInfo&) = delete;
-
-            OUString const name;
-            OUString const loader;
-            OUString const uri;
-            OUString const environment;
-            OUString const constructor;
-            OUString const prefix;
-            css::uno::Reference< css::uno::XComponentContext > const
+            OUString name;
+            OUString loader;
+            OUString uri;
+            OUString environment;
+            OUString constructor;
+            OUString prefix;
+            css::uno::Reference< css::uno::XComponentContext >
                 alienContext;
-            OUString const rdbFile;
+            OUString rdbFile;
             std::vector< OUString > services;
             std::vector< OUString > singletons;
         };
@@ -113,8 +110,7 @@ public:
                 css::uno::Reference< css::uno::XComponentContext > const &
                     alienContext,
                 OUString const & rdbFile):
-                info(
-                    new ImplementationInfo(
+                info( ImplementationInfo(
                         name, loader, uri, environment, constructorName, prefix,
                         alienContext, rdbFile)),
                 constructor(nullptr), status(STATUS_NEW), dispose(true)
@@ -128,7 +124,7 @@ public:
                     theFactory2,
                 css::uno::Reference< css::lang::XComponent > const &
                     theComponent):
-                info(new ImplementationInfo(name)), constructor(nullptr),
+                info(ImplementationInfo(name)), constructor(nullptr),
                 factory1(theFactory1), factory2(theFactory2),
                 component(theComponent), status(STATUS_LOADED), dispose(true)
             { assert(theFactory1.is() || theFactory2.is()); }
@@ -161,7 +157,7 @@ public:
             // ImplementationWrapper---also due to a
             // ServiceManager::createContentEnumeration call---and will be
             // loaded later).
-            std::shared_ptr< ImplementationInfo > info;
+            ImplementationInfo info;
             WrapperConstructorFn constructor;
             css::uno::Reference< css::lang::XSingleComponentFactory > factory1;
             css::uno::Reference< css::lang::XSingleServiceFactory > factory2;


More information about the Libreoffice-commits mailing list