1 From a04809a44c235bed854adc3bd49ca75b9673bf1f Mon Sep 17 00:00:00 2001
2 From: Milian Wolff <mail@milianw.de>
3 Date: Wed, 26 Nov 2014 13:20:05 +0100
4 Subject: [PATCH 13/30] Intern entity strings for table and column names.
6 This should drastically cut down on the amount of allocations done
7 by the AkonadiServer. Currently, the getters will do the conversion
8 from QLatin1String to QString on every call. By reusing the data
9 via a function-local static const QString object, we can eliminate
10 all of these allocations and increase the cache locality as well.
14 server/src/storage/entities-source.xsl | 56 +++++++++++++++++++++-------------
15 server/src/storage/entities.xsl | 4 +--
16 2 files changed, 36 insertions(+), 24 deletions(-)
18 diff --git a/server/src/storage/entities-source.xsl b/server/src/storage/entities-source.xsl
19 index 174cf4f..7090c31 100644
20 --- a/server/src/storage/entities-source.xsl
21 +++ b/server/src/storage/entities-source.xsl
22 @@ -214,36 +214,41 @@ void <xsl:value-of select="$className"/>::<xsl:call-template name="setter-signat
23 // SQL table information
24 <xsl:text>QString </xsl:text><xsl:value-of select="$className"/>::tableName()
26 - return QLatin1String( "<xsl:value-of select="$tableName"/>" );
27 + static const QString tableName = QLatin1String( "<xsl:value-of select="$tableName"/>" );
31 QStringList <xsl:value-of select="$className"/>::columnNames()
34 + static const QStringList columns = QStringList()
35 <xsl:for-each select="column">
36 - rv.append( QLatin1String( "<xsl:value-of select="@name"/>" ) );
37 + << <xsl:value-of select="@name"/>Column()
44 QStringList <xsl:value-of select="$className"/>::fullColumnNames()
47 + static const QStringList columns = QStringList()
48 <xsl:for-each select="column">
49 - rv.append( QLatin1String( "<xsl:value-of select="$tableName"/>.<xsl:value-of select="@name"/>" ) );
50 + << <xsl:value-of select="@name"/>FullColumnName()
57 <xsl:for-each select="column">
58 QString <xsl:value-of select="$className"/>::<xsl:value-of select="@name"/>Column()
60 - return QLatin1String( "<xsl:value-of select="@name"/>" );
61 + static const QString column = QLatin1String( "<xsl:value-of select="@name"/>" );
65 QString <xsl:value-of select="$className"/>::<xsl:value-of select="@name"/>FullColumnName()
67 - return tableName() + QLatin1String( ".<xsl:value-of select="@name"/>" );
68 + static const QString column = QLatin1String( "<xsl:value-of select="$tableName"/>.<xsl:value-of select="@name"/>" );
73 @@ -399,7 +404,6 @@ QVector<<xsl:value-of select="@table"/>> <xsl:value-of select="$className"
74 <xsl:variable name="relationName"><xsl:value-of select="@table1"/><xsl:value-of select="@table2"/>Relation</xsl:variable>
75 <xsl:variable name="rightSideClass"><xsl:value-of select="@table2"/></xsl:variable>
76 <xsl:variable name="rightSideEntity"><xsl:value-of select="@table2"/></xsl:variable>
77 -<xsl:variable name="rightSideTable"><xsl:value-of select="@table2"/>Table</xsl:variable>
79 // data retrieval for n:m relations
80 QVector<<xsl:value-of select="$rightSideClass"/>> <xsl:value-of select="$className"/>::<xsl:value-of select="concat(translate(substring(@table2,1,1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), substring(@table2,2))"/>s() const
81 @@ -408,14 +412,17 @@ QVector<<xsl:value-of select="$rightSideClass"/>> <xsl:value-of select="$c
83 return QVector<<xsl:value-of select="$rightSideClass"/>>();
85 - QueryBuilder qb( QLatin1String("<xsl:value-of select="$rightSideTable"/>"), QueryBuilder::Select );
86 + QueryBuilder qb( <xsl:value-of select="$rightSideClass"/>::tableName(), QueryBuilder::Select );
87 + static const QStringList columns = QStringList()
88 <xsl:for-each select="/database/table[@name = $rightSideEntity]/column">
89 - qb.addColumn( QLatin1String("<xsl:value-of select="$rightSideTable"/>.<xsl:value-of select="@name"/>" ) );
90 + << <xsl:value-of select="$rightSideClass"/>::<xsl:value-of select="@name"/>FullColumnName()
92 - qb.addJoin( QueryBuilder::InnerJoin, QLatin1String("<xsl:value-of select="$relationName"/>"),
93 - QLatin1String("<xsl:value-of select="$relationName"/>.<xsl:value-of select="@table2"/>_<xsl:value-of select="@column2"/>"),
94 - QLatin1String("<xsl:value-of select="$rightSideTable"/>.<xsl:value-of select="@column2"/>") );
95 - qb.addValueCondition( QLatin1String("<xsl:value-of select="$relationName"/>.<xsl:value-of select="@table1"/>_<xsl:value-of select="@column1"/>"), Query::Equals, id() );
97 + qb.addColumns(columns);
98 + qb.addJoin( QueryBuilder::InnerJoin, <xsl:value-of select="$relationName"/>::tableName(),
99 + <xsl:value-of select="$relationName"/>::rightFullColumnName(),
100 + <xsl:value-of select="$rightSideClass"/>::<xsl:value-of select="@column2"/>FullColumnName() );
101 + qb.addValueCondition( <xsl:value-of select="$relationName"/>::leftFullColumnName(), Query::Equals, id() );
104 akDebug() << "Error during selection of records from table <xsl:value-of select="@table1"/><xsl:value-of select="@table2"/>Relation"
105 @@ -546,7 +553,7 @@ bool <xsl:value-of select="$className"/>::update()
108 <xsl:if test="column[@name = 'id']">
109 - qb.addValueCondition( QLatin1String("id"), Query::Equals, id() );
110 + qb.addValueCondition( idColumn(), Query::Equals, id() );
114 @@ -622,27 +629,32 @@ void <xsl:value-of select="$className"/>::enableCache( bool enable )
115 // SQL table information
116 QString <xsl:value-of select="$className"/>::tableName()
118 - return QLatin1String( "<xsl:value-of select="$tableName"/>" );
119 + static const QString table = QLatin1String( "<xsl:value-of select="$tableName"/>" );
123 QString <xsl:value-of select="$className"/>::leftColumn()
125 - return QLatin1String( "<xsl:value-of select="@table1"/>_<xsl:value-of select="@column1"/>" );
126 + static const QString column = QLatin1String( "<xsl:value-of select="@table1"/>_<xsl:value-of select="@column1"/>" );
130 QString <xsl:value-of select="$className"/>::leftFullColumnName()
132 - return tableName() + QLatin1String( "." ) + leftColumn();
133 + static const QString column = QLatin1String( "<xsl:value-of select="$tableName"/>.<xsl:value-of select="@table1"/>_<xsl:value-of select="@column1"/>" );
137 QString <xsl:value-of select="$className"/>::rightColumn()
139 - return QLatin1String( "<xsl:value-of select="@table2"/>_<xsl:value-of select="@column2"/>" );
140 + static const QString column = QLatin1String( "<xsl:value-of select="@table2"/>_<xsl:value-of select="@column2"/>" );
144 QString <xsl:value-of select="$className"/>::rightFullColumnName()
146 - return tableName() + QLatin1String( "." ) + rightColumn();
147 + static const QString column = QLatin1String( "<xsl:value-of select="$tableName"/>.<xsl:value-of select="@table2"/>_<xsl:value-of select="@column2"/>" );
152 diff --git a/server/src/storage/entities.xsl b/server/src/storage/entities.xsl
153 index 033e292..8b0ed03 100644
154 --- a/server/src/storage/entities.xsl
155 +++ b/server/src/storage/entities.xsl
156 @@ -114,7 +114,7 @@ using namespace Akonadi::Server;
158 QVector<QString> Akonadi::Server::allDatabaseTables()
160 - static QVector<QString> allTables = QVector<QString>()
161 + static const QVector<QString> allTables = QVector<QString>()
162 <xsl:for-each select="database/table">
163 << QLatin1String( "<xsl:value-of select="@name"/>Table" )
165 @@ -182,7 +182,7 @@ set<xsl:value-of select="$methodName"/>( <xsl:call-template name="argument"/> )
167 QueryBuilder qb( tableName(), QueryBuilder::Select );
168 qb.addColumns( columnNames() );
169 - qb.addValueCondition( QLatin1String("<xsl:value-of select="$key"/>"), Query::Equals, <xsl:value-of select="$key"/> );
170 + qb.addValueCondition( <xsl:value-of select="$key"/>Column(), Query::Equals, <xsl:value-of select="$key"/> );
172 akDebug() << "Error during selection of record with <xsl:value-of select="$key"/>"
173 << <xsl:value-of select="$key"/> << "from table" << tableName()