Commit 65dd5ce8 authored by Marc Mutz's avatar Marc Mutz
Browse files

uic: don't use QStringLiteral in comparisons


For QLatin1String, operator== is overloaded, even for QStringRef,
so comparing to a latin-1 (C) string literal is efficient,
since strlen() is comparatively fast.

OTOH, QStringLiteral, when not using RVO, litters the code with
QString dtor calls, which are not inline. Worse, absent lambdas,
it even allocates memory.

So, just compare using QLatin1String instead.

Change-Id: Ice92d40342cb3939e8697d3f778f4421f5f967a1
Reviewed-by: default avatarThiago Macieira <thiago.macieira@intel.com>
Showing with 293 additions and 285 deletions
...@@ -238,8 +238,16 @@ ...@@ -238,8 +238,16 @@
</xsl:template> </xsl:template>
<!-- Format a string constant as QString(QLatin1Char('X')) or QStringLiteral("foo"), respectively --> <!-- Format a string constant for comparison as QLatin1String("foo") - they're all ascii-only -->
<xsl:template name="string-constant"> <xsl:template name="string-constant-for-comparison">
<xsl:param name="literal"/>
<xsl:text>QLatin1String("</xsl:text>
<xsl:value-of select="$literal"/>
<xsl:text>")</xsl:text>
</xsl:template>
<!-- Format a string constant for storage as QString(QLatin1Char('X')) or QLatin1String("foo"), respectively -->
<xsl:template name="string-constant-for-storage">
<xsl:param name="literal"/> <xsl:param name="literal"/>
<xsl:choose> <xsl:choose>
<xsl:when test="string-length($literal) &lt; 2"> <xsl:when test="string-length($literal) &lt; 2">
...@@ -286,7 +294,7 @@ ...@@ -286,7 +294,7 @@
</xsl:variable> </xsl:variable>
<xsl:text> if (name == </xsl:text> <xsl:text> if (name == </xsl:text>
<xsl:call-template name="string-constant"> <xsl:call-template name="string-constant-for-comparison">
<xsl:with-param name="literal" select="@name"/> <xsl:with-param name="literal" select="@name"/>
</xsl:call-template> </xsl:call-template>
<xsl:text>) {&endl;</xsl:text> <xsl:text>) {&endl;</xsl:text>
...@@ -332,7 +340,7 @@ ...@@ -332,7 +340,7 @@
<xsl:variable name="array" select="@maxOccurs = 'unbounded'"/> <xsl:variable name="array" select="@maxOccurs = 'unbounded'"/>
<xsl:text> if (tag == </xsl:text> <xsl:text> if (tag == </xsl:text>
<xsl:call-template name="string-constant"> <xsl:call-template name="string-constant-for-comparison">
<xsl:with-param name="literal" select="$lower-name"/> <xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template> </xsl:call-template>
<xsl:text>) {&endl;</xsl:text> <xsl:text>) {&endl;</xsl:text>
...@@ -465,7 +473,7 @@ ...@@ -465,7 +473,7 @@
<xsl:value-of select="$cap-name"/> <xsl:value-of select="$cap-name"/>
<xsl:text>())&endl;</xsl:text> <xsl:text>())&endl;</xsl:text>
<xsl:text> writer.writeAttribute(</xsl:text> <xsl:text> writer.writeAttribute(</xsl:text>
<xsl:call-template name="string-constant"> <xsl:call-template name="string-constant-for-storage">
<xsl:with-param name="literal" select="$lower-name"/> <xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template> </xsl:call-template>
...@@ -521,7 +529,7 @@ ...@@ -521,7 +529,7 @@
</xsl:variable> </xsl:variable>
<xsl:text> writer.writeTextElement(</xsl:text> <xsl:text> writer.writeTextElement(</xsl:text>
<xsl:call-template name="string-constant"> <xsl:call-template name="string-constant-for-storage">
<xsl:with-param name="literal" select="$camel-case-name"/> <xsl:with-param name="literal" select="$camel-case-name"/>
</xsl:call-template> </xsl:call-template>
<xsl:text>, </xsl:text> <xsl:text>, </xsl:text>
...@@ -542,7 +550,7 @@ ...@@ -542,7 +550,7 @@
<xsl:text>();&endl;</xsl:text> <xsl:text>();&endl;</xsl:text>
<xsl:text> if (v != 0) {&endl;</xsl:text> <xsl:text> if (v != 0) {&endl;</xsl:text>
<xsl:text> v->write(writer, </xsl:text> <xsl:text> v->write(writer, </xsl:text>
<xsl:call-template name="string-constant"> <xsl:call-template name="string-constant-for-storage">
<xsl:with-param name="literal" select="$lower-name"/> <xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template> </xsl:call-template>
<xsl:text>);&endl;</xsl:text> <xsl:text>);&endl;</xsl:text>
...@@ -601,7 +609,7 @@ ...@@ -601,7 +609,7 @@
<xsl:choose> <xsl:choose>
<xsl:when test="$xs-type-cat = 'pointer'"> <xsl:when test="$xs-type-cat = 'pointer'">
<xsl:text> v->write(writer, </xsl:text> <xsl:text> v->write(writer, </xsl:text>
<xsl:call-template name="string-constant"> <xsl:call-template name="string-constant-for-storage">
<xsl:with-param name="literal" select="$lower-name"/> <xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template> </xsl:call-template>
<xsl:text>);&endl;</xsl:text> <xsl:text>);&endl;</xsl:text>
...@@ -615,7 +623,7 @@ ...@@ -615,7 +623,7 @@
</xsl:variable> </xsl:variable>
<xsl:text> writer.writeTextElement(</xsl:text> <xsl:text> writer.writeTextElement(</xsl:text>
<xsl:call-template name="string-constant"> <xsl:call-template name="string-constant-for-storage">
<xsl:with-param name="literal" select="$lower-name"/> <xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template> </xsl:call-template>
<xsl:text>, </xsl:text> <xsl:text>, </xsl:text>
...@@ -634,7 +642,7 @@ ...@@ -634,7 +642,7 @@
<xsl:text> m_</xsl:text> <xsl:text> m_</xsl:text>
<xsl:value-of select="$camel-case-name"/> <xsl:value-of select="$camel-case-name"/>
<xsl:text>->write(writer, </xsl:text> <xsl:text>->write(writer, </xsl:text>
<xsl:call-template name="string-constant"> <xsl:call-template name="string-constant-for-storage">
<xsl:with-param name="literal" select="$lower-name"/> <xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template> </xsl:call-template>
<xsl:text>);&endl;</xsl:text> <xsl:text>);&endl;</xsl:text>
...@@ -647,7 +655,7 @@ ...@@ -647,7 +655,7 @@
</xsl:call-template> </xsl:call-template>
</xsl:variable> </xsl:variable>
<xsl:text> writer.writeTextElement(</xsl:text> <xsl:text> writer.writeTextElement(</xsl:text>
<xsl:call-template name="string-constant"> <xsl:call-template name="string-constant-for-storage">
<xsl:with-param name="literal" select="$lower-name"/> <xsl:with-param name="literal" select="$lower-name"/>
</xsl:call-template> </xsl:call-template>
<xsl:text>, </xsl:text> <xsl:text>, </xsl:text>
......
...@@ -142,7 +142,7 @@ ...@@ -142,7 +142,7 @@
</xsl:when> </xsl:when>
<xsl:when test="$xs-type='xs:boolean'"> <xsl:when test="$xs-type='xs:boolean'">
<xsl:value-of select="$val"/> <xsl:value-of select="$val"/>
<xsl:text> == QStringLiteral("true")</xsl:text> <xsl:text> == QLatin1String("true")</xsl:text>
</xsl:when> </xsl:when>
<xsl:when test="$xs-type='xs:long'"> <xsl:when test="$xs-type='xs:long'">
<xsl:value-of select="$val"/> <xsl:value-of select="$val"/>
......
This diff is collapsed.
Supports Markdown
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