Browse Source

Used {fmt} instead of string stream

Eyck Jentzsch 10 months ago
parent
commit
a21b2e57a2
1 changed files with 5 additions and 11 deletions
  1. 5
    11
      src/scv_tr_sqlite/scv_tr_sqlite.cpp

+ 5
- 11
src/scv_tr_sqlite/scv_tr_sqlite.cpp View File

@@ -20,6 +20,7 @@
20 20
 #include <stdexcept>
21 21
 #include <string>
22 22
 #include <vector>
23
+#include <fmt/format.h>
23 24
 // clang-format off
24 25
 #include "scv/scv_util.h"
25 26
 #include "scv/scv_introspection.h"
@@ -113,7 +114,6 @@ private:
113 114
 };
114 115
 // ----------------------------------------------------------------------------
115 116
 static SQLiteDB db;
116
-static ostringstream stringBuilder, queryBuilder;
117 117
 static vector<vector<uint64_t> *> concurrencyLevel;
118 118
 static sqlite3_stmt *stream_stmt, *gen_stmt, *tx_stmt, *evt_stmt, *attr_stmt, *rel_stmt;
119 119
 
@@ -164,10 +164,8 @@ static void dbCb(const scv_tr_db &_scv_tr_db, scv_tr_db::callback_reason reason,
164 164
                     "(id), sink INTEGER REFERENCES " TX_TABLE "(id));");
165 165
             db.exec("CREATE TABLE  IF NOT EXISTS " SIM_PROPS "(time_resolution INTEGER);");
166 166
             db.exec("BEGIN TRANSACTION");
167
-            queryBuilder.str("");
168
-            queryBuilder << "INSERT INTO " SIM_PROPS " (time_resolution) values ("
169
-                         << (long)(sc_get_time_resolution().to_seconds() * 1e15) << ");";
170
-            db.exec(queryBuilder.str());
167
+            db.exec(fmt::format(
168
+                    "INSERT INTO " SIM_PROPS " (time_resolution) values ({});", (long)(sc_get_time_resolution().to_seconds() * 1e15)));
171 169
             stream_stmt = db.prepare("INSERT INTO " STREAM_TABLE " (id, name, kind) values (@ID,@NAME,@KIND);");
172 170
             gen_stmt = db.prepare("INSERT INTO " GENERATOR_TABLE " (id,stream, name)"
173 171
                                   " values (@ID,@STRM_DI,@NAME);");
@@ -229,15 +227,11 @@ void recordAttribute(uint64_t id, EventType event, const string &name, data_type
229 227
 }
230 228
 // ----------------------------------------------------------------------------
231 229
 inline void recordAttribute(uint64_t id, EventType event, const string &name, data_type type, long long value) {
232
-    stringBuilder.str("");
233
-    stringBuilder << value;
234
-    recordAttribute(id, event, name, type, stringBuilder.str());
230
+    recordAttribute(id, event, name, type, fmt::format("{}", value));
235 231
 }
236 232
 // ----------------------------------------------------------------------------
237 233
 inline void recordAttribute(uint64_t id, EventType event, const string &name, data_type type, double value) {
238
-    stringBuilder.str("");
239
-    stringBuilder << value;
240
-    recordAttribute(id, event, name, type, stringBuilder.str());
234
+    recordAttribute(id, event, name, type, fmt::format("{}", value));
241 235
 }
242 236
 // ----------------------------------------------------------------------------
243 237
 static void recordAttributes(uint64_t id, EventType eventType, string &prefix, const scv_extensions_if *my_exts_p) {