From 75a862b887fb0b7ff633a396ee7f7f34c2c82964 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 1 Aug 2022 18:58:55 +0200 Subject: use more string_view when dealing with attributes which means we don't need to call strlen on them, since we already know how long they are. Change-Id: Iefc76f38a23250e87a65c27df3634d562464a760 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137679 Tested-by: Jenkins Reviewed-by: Noel Grandin --- oox/source/helper/attributelist.cxx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'oox') diff --git a/oox/source/helper/attributelist.cxx b/oox/source/helper/attributelist.cxx index 043f0689fd40..0215588b2b97 100644 --- a/oox/source/helper/attributelist.cxx +++ b/oox/source/helper/attributelist.cxx @@ -227,15 +227,15 @@ std::optional< sal_Int32 > AttributeList::getIntegerHex( sal_Int32 nAttrToken ) std::optional< bool > AttributeList::getBool( sal_Int32 nAttrToken ) const { - const char *pAttr; + std::string_view pAttr; // catch the common cases as quickly as possible first - bool bHasAttr = getAttribList()->getAsChar( nAttrToken, pAttr ); + bool bHasAttr = getAttribList()->getAsView( nAttrToken, pAttr ); if( !bHasAttr ) return std::optional< bool >(); - if( !strcmp( pAttr, "false" ) ) + if( pAttr == "false" ) return std::optional< bool >( false ); - if( !strcmp( pAttr, "true" ) ) + if( pAttr == "true" ) return std::optional< bool >( true ); // now for all the crazy stuff @@ -299,13 +299,10 @@ OUString AttributeList::getXString( sal_Int32 nAttrToken, const OUString& rDefau return getXString( nAttrToken ).value_or( rDefault ); } -const char* AttributeList::getChar( sal_Int32 nAttrToken ) const +std::string_view AttributeList::getView( sal_Int32 nAttrToken ) const { - const char* p = nullptr; - bool bValid = getAttribList()->getAsChar(nAttrToken, p); - if (!bValid) - p = nullptr; - + std::string_view p; + getAttribList()->getAsView(nAttrToken, p); return p; } -- cgit