Changeset View
Standalone View
utils.h
Show First 20 Lines • Show All 227 Lines • ▼ Show 20 Line(s) | |||||
228 | public: | 228 | public: | ||
229 | explicit Process(QObject *parent = nullptr); | 229 | explicit Process(QObject *parent = nullptr); | ||
230 | ~Process() override; | 230 | ~Process() override; | ||
231 | 231 | | |||
232 | protected: | 232 | protected: | ||
233 | void setupChildProcess() override; | 233 | void setupChildProcess() override; | ||
234 | }; | 234 | }; | ||
235 | 235 | | |||
236 | template <typename To, typename From> | ||||
237 | QVector<To> vector_cast(const QVector<From> &collection) | ||||
zzag: Is it okay to use "qvector_cast" name? | |||||
alexeymin: Looks as cool as your branch name | |||||
Technically Qt reserves itself the right to qsomething_functions. A name clash is unlikely, but I would have expected the function to be part of Qt when reading the code without having any background. In that sense I'd be for a kvector_cast (not really, I don't have a good name and don't like the cast much). gladhorn: Technically Qt reserves itself the right to qsomething_functions. A name clash is unlikely, but… | |||||
238 | { | ||||
239 | QVector<To> mapped; | ||||
240 | mapped.reserve(collection.size()); | ||||
For simple data types according to Qt docs resize is faster. It's a micro-optimization, but since the outputs are queried often maybe it's worth it. I assume we could use template specialization for AbstractOutput* as To type, or just use no template at all? Although having a templated qvector_cast is nice. romangg: For simple data types according to Qt docs resize is faster. It's a micro-optimization, but… | |||||
We could use std::enable_if or std::enable_if_t to specialize pointer types, however I don't think this level of complexity worth the trouble. We want to copy primitive and complex types. Append method costs only an if statement and an integer increment operation. We can stick with the current solution unless benchmarks show that we need to make concrete assumptions about internal implementation of qvector. zzag: We could use std::enable_if or std::enable_if_t to specialize pointer types, however I don't… | |||||
241 | std::copy(collection.constBegin(), collection.constEnd(), std::back_inserter(mapped)); | ||||
242 | return mapped; | ||||
243 | } | ||||
244 | | ||||
romangg: std::copy can't be used this way? | |||||
zzag: Good catch. | |||||
236 | } // namespace | 245 | } // namespace | ||
237 | 246 | | |||
238 | // Must be outside namespace | 247 | // Must be outside namespace | ||
239 | Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::StrutAreas) | 248 | Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::StrutAreas) | ||
240 | Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::QuickTileMode) | 249 | Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::QuickTileMode) | ||
241 | 250 | | |||
242 | #endif | 251 | #endif |
Is it okay to use "qvector_cast" name?