summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-10-02 12:02:40 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-10-23 13:24:27 +0200
commit5f46a7ad02aac2464fa45e4ecbc7cf4b85777664 (patch)
tree1a3661cedda5a8afebc60177d03c77de4c08e907 /sax
parenteb8e7a76328408bc12ff4abb761d7f44c27bf402 (diff)
FastSerializer: Faster write(OUString): add ascii check
Saves about 80m pcycles for 180k calls. Change-Id: I9c9b3bf5a076df56d1b5b87f0a85ac3404abe8a4
Diffstat (limited to 'sax')
-rw-r--r--sax/source/tools/fastserializer.cxx33
1 files changed, 32 insertions, 1 deletions
diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index 7afdc4d53cda..d8857689a543 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -53,6 +53,15 @@ static const char sEqualSignAndQuote[] = "=\"";
static const char sSpace[] = " ";
static const char sXmlHeader[] = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
+static bool lcl_isAscii(const OUString& sStr)
+{
+ for (sal_Int32 i = 0; i < sStr.getLength(); ++i)
+ if (sStr[i] & 0xff80)
+ return false;
+
+ return true;
+}
+
namespace sax_fastparser {
FastSaxSerializer::FastSaxSerializer( const css::uno::Reference< css::io::XOutputStream >& xOutputStream )
: maCachedOutputStream()
@@ -72,7 +81,29 @@ namespace sax_fastparser {
void FastSaxSerializer::write( const OUString& sOutput, bool bEscape )
{
- write( OUStringToOString(sOutput, RTL_TEXTENCODING_UTF8), bEscape );
+ if (!lcl_isAscii(sOutput))
+ {
+ write( OUStringToOString(sOutput, RTL_TEXTENCODING_UTF8), bEscape );
+ return ;
+ }
+
+ for (sal_Int32 i = 0; i < sOutput.getLength(); ++i)
+ {
+ char c = sOutput[ i ];
+ if (bEscape) switch( c )
+ {
+ case '<': writeBytes( "&lt;", 4 ); break;
+ case '>': writeBytes( "&gt;", 4 ); break;
+ case '&': writeBytes( "&amp;", 5 ); break;
+ case '\'': writeBytes( "&apos;", 6 ); break;
+ case '"': writeBytes( "&quot;", 6 ); break;
+ case '\n': writeBytes( "&#10;", 5 ); break;
+ case '\r': writeBytes( "&#13;", 5 ); break;
+ default: writeBytes( &c, 1 ); break;
+ }
+ else
+ writeBytes( &c, 1 );
+ }
}
void FastSaxSerializer::write( const OString& sOutput, bool bEscape )