[Libreoffice-commits] core.git: include/sax sc/source
Mohammed Abdul Azeem
azeemmysore at gmail.com
Sat Aug 12 14:04:50 UTC 2017
include/sax/fastattribs.hxx | 11 +++++
sc/source/filter/xml/xmlcelli.cxx | 4 +-
sc/source/filter/xml/xmlexternaltabi.cxx | 2 -
sc/source/filter/xml/xmlimprt.cxx | 59 +++++++++++++++++++------------
sc/source/filter/xml/xmlimprt.hxx | 5 --
5 files changed, 51 insertions(+), 30 deletions(-)
New commits:
commit dfac13b483ba38ce6f61cd0a1e5757c6a08ab296
Author: Mohammed Abdul Azeem <azeemmysore at gmail.com>
Date: Wed Aug 9 21:36:12 2017 +0530
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/40928
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/include/sax/fastattribs.hxx b/include/sax/fastattribs.hxx
index 8b669fe26a17..0a7d8712fb17 100644
--- a/include/sax/fastattribs.hxx
+++ b/include/sax/fastattribs.hxx
@@ -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());
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index c3edfdbeac03..9de47677dd1a 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -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;
diff --git a/sc/source/filter/xml/xmlexternaltabi.cxx b/sc/source/filter/xml/xmlexternaltabi.cxx
index 70fc010667f2..57cbbfda420d 100644
--- a/sc/source/filter/xml/xmlexternaltabi.cxx
+++ b/sc/source/filter/xml/xmlexternaltabi.cxx
@@ -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:
diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx
index 339b433dc919..2893c9e354e1 100644
--- a/sc/source/filter/xml/xmlimprt.cxx
+++ b/sc/source/filter/xml/xmlimprt.cxx
@@ -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()
diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx
index a83c31af35b8..f3b610b2ce24 100644
--- a/sc/source/filter/xml/xmlimprt.hxx
+++ b/sc/source/filter/xml/xmlimprt.hxx
@@ -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; }
More information about the Libreoffice-commits
mailing list