Verbessere die CMake-Konfiguration zur Unterstützung von C++23, indem die Compiler-Auswahl dynamisch auf GCC 15 oder 13 basiert. Optimiere die Compiler-Flags für Leistung. In der Datenbankabfrage und im DirectorWorker werden konstante Referenzen und string_view verwendet, um die Leistung zu steigern. Reserviere Speicher für Vektoren in main.cpp zur Effizienzsteigerung.
This commit is contained in:
committed by
Torsten (PC)
parent
1f43df6d41
commit
4bafc3a61c
@@ -28,14 +28,19 @@ Database::query(const std::string &sql)
|
||||
pqxx::work txn(*connection_);
|
||||
pqxx::result r = txn.exec(sql);
|
||||
txn.commit();
|
||||
for (auto row : r) {
|
||||
|
||||
// Pre-allocate memory for better performance
|
||||
rows.reserve(r.size());
|
||||
|
||||
for (const auto& row : r) {
|
||||
std::map<std::string, std::string> oneRow;
|
||||
|
||||
for (auto f = 0u; f < row.size(); f++) {
|
||||
std::string colName = r.column_name(f);
|
||||
std::string value = row[f].c_str() ? row[f].c_str() : "";
|
||||
oneRow[colName] = value;
|
||||
const std::string colName = r.column_name(f);
|
||||
const char* value = row[f].c_str();
|
||||
oneRow.emplace(colName, value ? value : "");
|
||||
}
|
||||
rows.push_back(std::move(oneRow));
|
||||
rows.emplace_back(std::move(oneRow));
|
||||
}
|
||||
} catch (const std::exception &ex) {
|
||||
std::cerr << "[Database] query-Fehler: " << ex.what() << "\nSQL: " << sql << std::endl;
|
||||
@@ -82,8 +87,13 @@ Database::FieldList Database::execute(const std::string& stmtName,
|
||||
out.reserve(res.size());
|
||||
for (const auto& row : res) {
|
||||
std::unordered_map<std::string, std::string> m;
|
||||
m.reserve(row.size()); // Pre-allocate for better performance
|
||||
|
||||
for (const auto& f : row) {
|
||||
m.emplace(f.name(), f.is_null() ? std::string{} : std::string(f.c_str()));
|
||||
// Use string_view for better performance (C++17+)
|
||||
const std::string_view name = f.name();
|
||||
const char* value = f.c_str();
|
||||
m.emplace(name, f.is_null() ? std::string{} : std::string(value));
|
||||
}
|
||||
out.emplace_back(std::move(m));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user