Kaydet (Commit) 1094fedf authored tarafından Noel Grandin's avatar Noel Grandin

getUtf8TokenName can return by const ref

and avoid some reference-counting in a hot path

Change-Id: I7f5fd7f8f5f9076eb5f8d60118afa8e3ac8a5e6c
Reviewed-on: https://gerrit.libreoffice.org/38129Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 649228f9
......@@ -42,13 +42,13 @@ public:
static sal_Int32 getTokenFromUnicode( const OUString& rUnicodeName );
/** Returns the UTF8 name of the passed token identifier as byte sequence. */
css::uno::Sequence< sal_Int8 >
css::uno::Sequence< sal_Int8 > const &
getUtf8TokenName( sal_Int32 nToken ) const
{
SAL_WARN_IF(nToken < 0 || nToken >= XML_TOKEN_COUNT, "oox", "Wrong nToken parameter");
if (0 <= nToken && nToken < XML_TOKEN_COUNT)
return maTokenNames[ nToken ];
return css::uno::Sequence< sal_Int8 >();
return EMPTY_BYTE_SEQ;
}
/** Returns the token identifier for the passed UTF8 token name. */
......@@ -75,6 +75,7 @@ public:
private:
static sal_Int32 getTokenPerfectHash( const char *pToken, sal_Int32 nLength );
static const css::uno::Sequence< sal_Int8 > EMPTY_BYTE_SEQ;
typedef ::std::vector< css::uno::Sequence< sal_Int8 > > TokenNameVector;
......
......@@ -27,12 +27,12 @@ public:
~TokenMap();
/** Returns the UTF-8 name of the passed token identifier as byte sequence. */
css::uno::Sequence< sal_Int8 > getUtf8TokenName( sal_Int32 nToken ) const
css::uno::Sequence< sal_Int8 > const & getUtf8TokenName( sal_Int32 nToken ) const
{
SAL_WARN_IF(nToken < 0 || nToken >= XML_TOKEN_COUNT, "xmloff", "Wrong nToken parameter");
if( 0 <= nToken && nToken < XML_TOKEN_COUNT )
return maTokenNames[ nToken ];
return css::uno::Sequence< sal_Int8 >();
return EMPTY_BYTE_SEQ;
}
/** Returns the token identifier for the passed UTF-8 token name. */
......@@ -52,6 +52,8 @@ private:
static sal_Int32 getTokenPerfectHash( const char *pToken, sal_Int32 nLength );
std::vector< css::uno::Sequence< sal_Int8 > > maTokenNames;
static const css::uno::Sequence< sal_Int8 > EMPTY_BYTE_SEQ;
};
struct StaticTokenMap : public rtl::Static< TokenMap, StaticTokenMap > {};
......
......@@ -103,7 +103,7 @@ public:
const css::awt::Size &aSize );
sal_Int32 getShapePresetType() const { return mnShapePresetType; }
css::uno::Sequence< sal_Int8 > getShapePresetTypeName() const;
css::uno::Sequence< sal_Int8 > const & getShapePresetTypeName() const;
void setShapePresetType( sal_Int32 nShapePresetType ){ mnShapePresetType = nShapePresetType; };
bool getShapeTypeOverride(){ return mbShapeTypeOverride; };
void setShapeTypeOverride( bool bShapeTypeOverride ) { mbShapeTypeOverride = bShapeTypeOverride; };
......
......@@ -52,7 +52,7 @@ CustomShapeProperties::~CustomShapeProperties()
{
}
uno::Sequence< sal_Int8 > CustomShapeProperties::getShapePresetTypeName() const
uno::Sequence< sal_Int8 > const & CustomShapeProperties::getShapePresetTypeName() const
{
return StaticTokenMap::get().getUtf8TokenName( mnShapePresetType );
}
......
......@@ -752,7 +752,7 @@ Reference< XShape > const & Shape::createAndInsert(
sal_Int32 length = aGrabBag.getLength();
aGrabBag.realloc( length+1);
aGrabBag[length].Name = "mso-orig-shape-type";
const uno::Sequence< sal_Int8 > aNameSeq =
uno::Sequence< sal_Int8 > const & aNameSeq =
mpCustomShapePropertiesPtr->getShapePresetTypeName();
OUString sShapePresetTypeName(reinterpret_cast< const char* >(
aNameSeq.getConstArray()), aNameSeq.getLength(), RTL_TEXTENCODING_UTF8);
......
......@@ -58,7 +58,7 @@ AttributeListBuilder::AttributeListBuilder( const uno::Reference< xml::sax::XFas
OString tokenToString( int token )
{
const uno::Sequence< sal_Int8 > aTokenNameSeq = StaticTokenMap::get().getUtf8TokenName( token & TOKEN_MASK );
uno::Sequence< sal_Int8 > const & aTokenNameSeq = StaticTokenMap::get().getUtf8TokenName( token & TOKEN_MASK );
OString tokenname( reinterpret_cast< const char* >( aTokenNameSeq.getConstArray() ), aTokenNameSeq.getLength() );
if( tokenname.isEmpty())
tokenname = "???";
......
......@@ -43,6 +43,8 @@ namespace {
#endif
} // namespace
const css::uno::Sequence< sal_Int8 > TokenMap::EMPTY_BYTE_SEQ;
TokenMap::TokenMap() :
maTokenNames( static_cast< size_t >( XML_TOKEN_COUNT ) )
{
......
......@@ -32,6 +32,8 @@ namespace token {
using namespace css;
const css::uno::Sequence< sal_Int8 > TokenMap::EMPTY_BYTE_SEQ;
TokenMap::TokenMap() :
maTokenNames( static_cast< size_t >( XML_TOKEN_COUNT ) )
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment