Kaydet (Commit) dfac13b4 authored tarafından Mohammed Abdul Azeem's avatar Mohammed Abdul Azeem Kaydeden (comit) Michael Meeks

Avoiding unnecessary OUString allocation:

Using direct strcmp instead of mapping. This is one
of the hotspots and will help improve performance.

Change-Id: I97a452984d53a6746f477ffe4be2806d9e89eee4
Reviewed-on: https://gerrit.libreoffice.org/40928Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 6d34c6ee
......@@ -162,7 +162,16 @@ public:
mrList.AttributeValueLength(mnIdx),
RTL_TEXTENCODING_UTF8);
}
const char* toCString() const
{
assert(mnIdx < mrList.maAttributeTokens.size());
return mrList.getFastAttributeValue(mnIdx);
}
sal_Int32 getLength() const
{
assert(mnIdx < mrList.maAttributeTokens.size());
return mrList.AttributeValueLength(mnIdx);
}
bool isString(const char *str) const
{
assert(mnIdx < mrList.maAttributeTokens.size());
......
......@@ -196,14 +196,14 @@ ScXMLTableRowCellContext::ScXMLTableRowCellContext( ScXMLImport& rImport,
std::max( it.toInt32(), static_cast<sal_Int32>(1) ) ));
break;
case XML_ELEMENT( OFFICE, XML_VALUE_TYPE ):
nCellType = GetScImport().GetCellType(it.toString());
nCellType = ScXMLImport::GetCellType(it.toCString(), it.getLength());
bIsEmpty = false;
break;
case XML_ELEMENT( CALC_EXT, XML_VALUE_TYPE ):
if(it.isString( "error" ) )
mbErrorValue = true;
else
nCellType = GetScImport().GetCellType(it.toString());
nCellType = ScXMLImport::GetCellType(it.toCString(), it.getLength());
bIsEmpty = false;
mbNewValueType = true;
break;
......
......@@ -271,7 +271,7 @@ ScXMLExternalRefCellContext::ScXMLExternalRefCellContext(
break;
case XML_TOK_TABLE_ROW_CELL_ATTR_VALUE_TYPE:
{
mnCellType = mrScImport.GetCellType( it.toString() );
mnCellType = ScXMLImport::GetCellType( it.toCString(), it.getLength() );
}
break;
case XML_TOK_TABLE_ROW_CELL_ATTR_VALUE:
......
......@@ -809,23 +809,6 @@ ScXMLImport::ScXMLImport(
GetXMLToken( XML_NP_PRESENTATION ),
GetXMLToken( XML_N_PRESENTATION ),
XML_NAMESPACE_PRESENTATION );
// initialize cell type map.
const struct { XMLTokenEnum _token; sal_Int16 _type; } aCellTypePairs[] =
{
{ XML_FLOAT, util::NumberFormat::NUMBER },
{ XML_STRING, util::NumberFormat::TEXT },
{ XML_TIME, util::NumberFormat::TIME },
{ XML_DATE, util::NumberFormat::DATETIME },
{ XML_PERCENTAGE, util::NumberFormat::PERCENT },
{ XML_CURRENCY, util::NumberFormat::CURRENCY },
{ XML_BOOLEAN, util::NumberFormat::LOGICAL }
};
for (const auto & aCellTypePair : aCellTypePairs)
{
aCellTypeMap.emplace(
GetXMLToken(aCellTypePair._token), aCellTypePair._type);
}
}
ScXMLImport::~ScXMLImport() throw()
......@@ -1021,13 +1004,45 @@ ScDocumentImport& ScXMLImport::GetDoc()
return *mpDocImport;
}
sal_Int16 ScXMLImport::GetCellType(const OUString& rStrValue) const
sal_Int16 ScXMLImport::GetCellType(const char* rStrValue, const sal_Int32 nStrLength)
{
CellTypeMap::const_iterator itr = aCellTypeMap.find(rStrValue);
if (itr != aCellTypeMap.end())
return itr->second;
sal_Int16 nCellType = util::NumberFormat::UNDEFINED;
if (rStrValue != nullptr)
{
switch (rStrValue[0])
{
case 'b':
if (nStrLength == 7 && !strcmp(rStrValue, "boolean"))
nCellType = util::NumberFormat::LOGICAL;
break;
case 'c':
if (nStrLength == 8 && !strcmp(rStrValue, "currency"))
nCellType = util::NumberFormat::CURRENCY;
break;
case 'd':
if (nStrLength == 4 && !strcmp(rStrValue, "date"))
nCellType = util::NumberFormat::DATETIME;
break;
case 'f':
if (nStrLength == 5 && !strcmp(rStrValue, "float"))
nCellType = util::NumberFormat::NUMBER;
break;
case 'p':
if (nStrLength == 10 && !strcmp(rStrValue, "percentage"))
nCellType = util::NumberFormat::PERCENT;
break;
case 's':
if (nStrLength == 6 && !strcmp(rStrValue, "string"))
nCellType = util::NumberFormat::TEXT;
break;
case 't':
if (nStrLength == 4 && !strcmp(rStrValue, "time"))
nCellType = util::NumberFormat::TIME;
break;
}
}
return util::NumberFormat::UNDEFINED;
return nCellType;
}
XMLShapeImportHelper* ScXMLImport::CreateShapeImport()
......
......@@ -577,11 +577,8 @@ class ScXMLImport: public SvXMLImport
ScXMLImport(const ScXMLImport&) = delete;
const ScXMLImport& operator=(const ScXMLImport&) = delete;
typedef std::unordered_map< OUString, sal_Int16, OUStringHash > CellTypeMap;
typedef ::std::map<SCTAB, std::unique_ptr<ScMyNamedExpressions>> SheetNamedExpMap;
CellTypeMap aCellTypeMap;
ScDocument* pDoc;
std::unique_ptr<ScDocumentImport> mpDocImport;
std::unique_ptr<ScCompiler> mpComp; // For error-checking of cached string cell values.
......@@ -738,7 +735,7 @@ public:
bool IsStylesOnlyMode() const { return !bLoadDoc; }
sal_Int16 GetCellType(const OUString& rStrValue) const;
static sal_Int16 GetCellType(const char* rStrValue, const sal_Int32 nStrLength);
const rtl::Reference < XMLPropertySetMapper >& GetCellStylesPropertySetMapper() const { return xCellStylesPropertySetMapper; }
const rtl::Reference < XMLPropertySetMapper >& GetColumnStylesPropertySetMapper() const { return xColumnStylesPropertySetMapper; }
......
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