From da096e3b0ab93b43c5d33aeed0b90d7fb151f6dc Mon Sep 17 00:00:00 2001 From: Matteo Casalin Date: Fri, 21 Dec 2018 18:23:34 +0100 Subject: Reduce OUString operations and use indexed getToken Change-Id: I41bc361cbbbf1a446138354eb7bf80729a79bc1f Reviewed-on: https://gerrit.libreoffice.org/65673 Tested-by: Jenkins Reviewed-by: Matteo Casalin --- cpputools/source/unoexe/unoexe.cxx | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'cpputools') 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 (;;) { -- cgit