11#include " orm/query/grammars/postgresgrammar.hpp"
22
3- #include " orm/macros/threadlocal.hpp"
43#include " orm/query/querybuilder.hpp"
54
65TINYORM_BEGIN_COMMON_NAMESPACE
@@ -113,18 +112,20 @@ PostgresGrammar::getCompileMap() const
113112 'this' reference and the compileMethod rvalue reference in the following lambda
114113 and simply save std::function<> in the SelectComponentValue's compileMethod data
115114 member. */
116- const auto bind = [this ](auto &&compileMethod)
115+ const auto bind = [](auto &&compileMethod)
117116 {
118- return [this ,
119- compileMethod = std::forward<decltype (compileMethod)>(compileMethod)]
120- (const auto &query)
117+ return [compileMethod = std::forward<decltype (compileMethod)>(compileMethod)]
118+ (const Grammar &grammar, const QueryBuilder &query)
121119 {
122- return std::invoke (compileMethod, this , query);
120+ /* We can be at 100% sure that this is the PostgresGrammar instance because
121+ this method is virtual; used the reinterpret_cast<> to avoid useless
122+ and slower dynamic_cast<>. */
123+ return std::invoke (compileMethod,
124+ reinterpret_cast <const PostgresGrammar &>(grammar), query);
123125 };
124126 };
125127
126128 // Pointers to a where member methods by whereType, yes yes c++ π
127- T_THREAD_LOCAL
128129 static const QMap<SelectComponentType, SelectComponentValue> cached {
129130 {SelectComponentType::AGGREGATE, {bind (&PostgresGrammar::compileAggregate),
130131 [](const auto &query)
@@ -155,28 +156,30 @@ PostgresGrammar::getCompileMap() const
155156 return cached;
156157}
157158
158- const std::function<QString( const WhereConditionItem &)> &
159+ const Grammar::WhereMemFn &
159160PostgresGrammar::getWhereMethod (const WhereType whereType) const
160161{
161162 /* Needed, because some compileXx() methods are overloaded, this way I will capture
162163 'this' reference and the compileMethod rvalue reference in the following lambda
163164 and simply save std::function<> in the SelectComponentValue's compileMethod data
164165 member. */
165- const auto bind = [this ](auto &&compileMethod)
166+ const auto bind = [](auto &&compileMethod)
166167 {
167- return [this ,
168- compileMethod = std::forward<decltype (compileMethod)>(compileMethod)]
169- (const auto &query)
168+ return [compileMethod = std::forward<decltype (compileMethod)>(compileMethod)]
169+ (const Grammar &grammar, const WhereConditionItem &query)
170170 {
171- return std::invoke (compileMethod, this , query);
171+ /* We can be at 100% sure that this is the PostgresGrammar instance because
172+ this method is virtual; used the reinterpret_cast<> to avoid useless
173+ and slower dynamic_cast<>. */
174+ return std::invoke (compileMethod,
175+ reinterpret_cast <const PostgresGrammar &>(grammar), query);
172176 };
173177 };
174178
175179 // Pointers to a where member methods by whereType, yes yes c++ π
176180 // An order has to be the same as in enum struct WhereType
177181 // FUTURE QHash would has faster lookup, I should choose QHash, fix also another Grammars silverx
178- T_THREAD_LOCAL
179- static const QVector<std::function<QString (const WhereConditionItem &)>> cached {
182+ static const QVector<WhereMemFn> cached {
180183 bind (&PostgresGrammar::whereBasic),
181184 bind (&PostgresGrammar::whereNested),
182185 bind (&PostgresGrammar::whereColumn),
@@ -197,7 +200,6 @@ PostgresGrammar::getWhereMethod(const WhereType whereType) const
197200 bind (&PostgresGrammar::whereYear),
198201 };
199202
200- T_THREAD_LOCAL
201203 static const auto size = cached.size ();
202204
203205 // Check if whereType is in the range, just for sure π
0 commit comments