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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Dec 28 16:10:39 UTC 2018


 cpputools/source/unoexe/unoexe.cxx |   24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

New commits:
commit da096e3b0ab93b43c5d33aeed0b90d7fb151f6dc
Author:     Matteo Casalin <matteo.casalin at yahoo.com>
AuthorDate: Fri Dec 21 18:23:34 2018 +0100
Commit:     Matteo Casalin <matteo.casalin at yahoo.com>
CommitDate: Fri Dec 28 17:10:16 2018 +0100

    Reduce OUString operations and use indexed getToken
    
    Change-Id: I41bc361cbbbf1a446138354eb7bf80729a79bc1f
    Reviewed-on: https://gerrit.libreoffice.org/65673
    Tested-by: Jenkins
    Reviewed-by: Matteo Casalin <matteo.casalin at yahoo.com>

diff --git a/cpputools/source/unoexe/unoexe.cxx b/cpputools/source/unoexe/unoexe.cxx
index c6db2c891db2..8392ace881d0 100644
--- a/cpputools/source/unoexe/unoexe.cxx
+++ b/cpputools/source/unoexe/unoexe.cxx
@@ -427,16 +427,24 @@ SAL_IMPLEMENT_MAIN()
 
         if (!aUnoUrl.isEmpty()) // accepting connections
         {
-            sal_Int32 nIndex = 0, nTokens = 0;
-            do { aUnoUrl.getToken( 0, ';', nIndex ); nTokens++; } while( nIndex != -1 );
-            if (nTokens != 3 || aUnoUrl.getLength() < 10 ||
-                !aUnoUrl.copy( 0, 4 ).equalsIgnoreAsciiCase( "uno:" ))
+            if (aUnoUrl.getLength() < 10 || !aUnoUrl.startsWithIgnoreAsciiCase( "uno:" ))
+            {
+                throw RuntimeException("illegal uno url given!" );
+            }
+
+            sal_Int32 nIndex = 4; // skip initial "uno:"
+            bool bTooFewTokens {false};
+            const OUString aConnectDescr{ aUnoUrl.getToken( 0, ';', nIndex ) }; // uno:CONNECTDESCR;iiop;InstanceName
+            if (nIndex<0) bTooFewTokens = true;
+            const OUString aUnoUrlToken{ aUnoUrl.getToken( 0, ';', nIndex ) };
+            if (nIndex<0) bTooFewTokens = true;
+            const OUString aInstanceName{ aUnoUrl.getToken( 0, ';', nIndex ) };
+
+            // Exactly 3 tokens are required
+            if (bTooFewTokens || nIndex>0)
             {
                 throw RuntimeException("illegal uno url given!" );
             }
-            nIndex = 0;
-            OUString aConnectDescr( aUnoUrl.getToken( 0, ';', nIndex ).copy( 4 ) ); // uno:CONNECTDESCR;iiop;InstanceName
-            OUString aInstanceName( aUnoUrl.getToken( 1, ';', nIndex ) );
 
             Reference< XAcceptor > xAcceptor = Acceptor::create(xContext);
 
@@ -454,8 +462,6 @@ SAL_IMPLEMENT_MAIN()
                 xContext, aImplName, aLocation, aServiceName, aInitParams,
                 bSingleInstance, aInstanceName ) );
 
-            nIndex = 0;
-            OUString aUnoUrlToken( aUnoUrl.getToken( 1, ';', nIndex ) );
             // coverity[loop_top] - not really an infinite loop, we can be instructed to exit via the connection
             for (;;)
             {


More information about the Libreoffice-commits mailing list