]>
Commit | Line | Data |
---|---|---|
8a8f9fb3 AM |
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. | |
5 | ||
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. | |
11 | ||
12 | REVIEW: 121255 | |
13 | --- | |
14 | server/src/storage/entities-source.xsl | 56 +++++++++++++++++++++------------- | |
15 | server/src/storage/entities.xsl | 4 +-- | |
16 | 2 files changed, 36 insertions(+), 24 deletions(-) | |
17 | ||
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() | |
25 | { | |
26 | - return QLatin1String( "<xsl:value-of select="$tableName"/>" ); | |
27 | + static const QString tableName = QLatin1String( "<xsl:value-of select="$tableName"/>" ); | |
28 | + return tableName; | |
29 | } | |
30 | ||
31 | QStringList <xsl:value-of select="$className"/>::columnNames() | |
32 | { | |
33 | - QStringList rv; | |
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() | |
38 | </xsl:for-each> | |
39 | - return rv; | |
40 | + ; | |
41 | + return columns; | |
42 | } | |
43 | ||
44 | QStringList <xsl:value-of select="$className"/>::fullColumnNames() | |
45 | { | |
46 | - QStringList rv; | |
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() | |
51 | </xsl:for-each> | |
52 | - return rv; | |
53 | + ; | |
54 | + return columns; | |
55 | } | |
56 | ||
57 | <xsl:for-each select="column"> | |
58 | QString <xsl:value-of select="$className"/>::<xsl:value-of select="@name"/>Column() | |
59 | { | |
60 | - return QLatin1String( "<xsl:value-of select="@name"/>" ); | |
61 | + static const QString column = QLatin1String( "<xsl:value-of select="@name"/>" ); | |
62 | + return column; | |
63 | } | |
64 | ||
65 | QString <xsl:value-of select="$className"/>::<xsl:value-of select="@name"/>FullColumnName() | |
66 | { | |
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"/>" ); | |
69 | + return column; | |
70 | } | |
71 | </xsl:for-each> | |
72 | ||
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> | |
78 | ||
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 | |
82 | if ( !db.isOpen() ) | |
83 | return QVector<<xsl:value-of select="$rightSideClass"/>>(); | |
84 | ||
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() | |
91 | </xsl:for-each> | |
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() ); | |
96 | + ; | |
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() ); | |
102 | ||
103 | if ( !qb.exec() ) { | |
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() | |
106 | </xsl:for-each> | |
107 | ||
108 | <xsl:if test="column[@name = 'id']"> | |
109 | - qb.addValueCondition( QLatin1String("id"), Query::Equals, id() ); | |
110 | + qb.addValueCondition( idColumn(), Query::Equals, id() ); | |
111 | </xsl:if> | |
112 | ||
113 | if ( !qb.exec() ) { | |
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() | |
117 | { | |
118 | - return QLatin1String( "<xsl:value-of select="$tableName"/>" ); | |
119 | + static const QString table = QLatin1String( "<xsl:value-of select="$tableName"/>" ); | |
120 | + return table; | |
121 | } | |
122 | ||
123 | QString <xsl:value-of select="$className"/>::leftColumn() | |
124 | { | |
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"/>" ); | |
127 | + return column; | |
128 | } | |
129 | ||
130 | QString <xsl:value-of select="$className"/>::leftFullColumnName() | |
131 | { | |
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"/>" ); | |
134 | + return column; | |
135 | } | |
136 | ||
137 | QString <xsl:value-of select="$className"/>::rightColumn() | |
138 | { | |
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"/>" ); | |
141 | + return column; | |
142 | } | |
143 | ||
144 | QString <xsl:value-of select="$className"/>::rightFullColumnName() | |
145 | { | |
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"/>" ); | |
148 | + return column; | |
149 | } | |
150 | </xsl:template> | |
151 | ||
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; | |
157 | ||
158 | QVector<QString> Akonadi::Server::allDatabaseTables() | |
159 | { | |
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" ) | |
164 | </xsl:for-each> | |
165 | @@ -182,7 +182,7 @@ set<xsl:value-of select="$methodName"/>( <xsl:call-template name="argument"/> ) | |
166 | ||
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"/> ); | |
171 | if ( !qb.exec() ) { | |
172 | akDebug() << "Error during selection of record with <xsl:value-of select="$key"/>" | |
173 | << <xsl:value-of select="$key"/> << "from table" << tableName() | |
174 | -- | |
175 | 2.1.0 | |
176 |