// intern the brushes, to reuse them across items which can be thousands
// otherwise we'd end up with dozens of allocations and higher memory
// consumption
- static QVector<QBrush> brushes;
- if (brushes.isEmpty()) {
+ static const QVector<QBrush> brushes = []() -> QVector<QBrush> {
+ QVector<QBrush> brushes;
std::generate_n(std::back_inserter(brushes), 100, []() {
return QColor(0, 190 + 50 * qreal(rand()) / RAND_MAX, 210 * qreal(rand()) / RAND_MAX, 125);
});
- }
+ return brushes;
+ }();
return brushes.at(rand() % brushes.size());
}