Skip to content

Commit

Permalink
More clang-tidy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Dec 19, 2024
1 parent 06c2022 commit 4c2b9f8
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 35 deletions.
4 changes: 2 additions & 2 deletions cpp/DBHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ void DBHostObject::on_rollback() {
}

void DBHostObject::on_update(const std::string &table,
const std::string &operation, int row_id) {
const std::string &operation, long long row_id) {
if (update_hook_callback != nullptr) {
invoker->invokeAsync(
[this, callback = update_hook_callback, table, operation, row_id] {
auto res = jsi::Object(rt);
res.setProperty(rt, "table", jsi::String::createFromUtf8(rt, table));
res.setProperty(rt, "operation",
jsi::String::createFromUtf8(rt, operation));
res.setProperty(rt, "rowId", jsi::Value(row_id));
res.setProperty(rt, "rowId", jsi::Value(static_cast<double>(row_id)));

callback->asObject(rt).asFunction(rt).call(rt, res);
});
Expand Down
14 changes: 8 additions & 6 deletions cpp/DBHostObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,23 @@ class JSI_EXPORT DBHostObject : public jsi::HostObject {
std::string &auth_token, int sync_interval);
#endif

std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt);
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) override;
void set(jsi::Runtime &rt, const jsi::PropNameID &name,
const jsi::Value &value);
void on_update(const std::string& table, const std::string &operation, int row_id);
const jsi::Value &value) override;
void on_update(const std::string &table, const std::string &operation,
long long row_id);
void on_commit();
void on_rollback();
void invalidate();
~DBHostObject();
~DBHostObject() override;

private:
std::set<std::shared_ptr<ReactiveQuery>> pending_reactive_queries;
void auto_register_update_hook();
void create_jsi_functions();
void flush_pending_reactive_queries(const std::shared_ptr<jsi::Value>& resolve);
void
flush_pending_reactive_queries(const std::shared_ptr<jsi::Value> &resolve);

std::unordered_map<std::string, jsi::Value> function_map;
std::string base_path;
Expand Down
11 changes: 6 additions & 5 deletions cpp/DumbHostObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ namespace jsi = facebook::jsi;

class JSI_EXPORT DumbHostObject : public jsi::HostObject {
public:
DumbHostObject() {};
DumbHostObject() = default;

DumbHostObject(std::shared_ptr<std::vector<SmartHostObject>> metadata);
explicit DumbHostObject(
std::shared_ptr<std::vector<SmartHostObject>> metadata);

std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt);
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;

jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) override;

void set(jsi::Runtime &rt, const jsi::PropNameID &name,
const jsi::Value &value);
const jsi::Value &value) override;

std::vector<JSVariant> values;

Expand Down
17 changes: 9 additions & 8 deletions cpp/PreparedStatementHostObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#endif
#include "ThreadPool.h"
#include <string>
#include <utility>

namespace opsqlite {
namespace jsi = facebook::jsi;
Expand All @@ -29,26 +30,26 @@ class PreparedStatementHostObject : public jsi::HostObject {
sqlite3 *db, std::string name, sqlite3_stmt *stmt,
std::shared_ptr<react::CallInvoker> js_call_invoker,
std::shared_ptr<ThreadPool> thread_pool)
: _db(db), _name(name), _stmt(stmt), _js_call_invoker(js_call_invoker),
_thread_pool(thread_pool) {};
: _db(db), _name(std::move(name)), _stmt(stmt), _js_call_invoker(std::move(js_call_invoker)),
_thread_pool(std::move(thread_pool)) {};
#endif
virtual ~PreparedStatementHostObject();
~PreparedStatementHostObject() override;

std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt);
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;

jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) override;

private:
std::shared_ptr<react::CallInvoker> _js_call_invoker;
std::shared_ptr<ThreadPool> _thread_pool;
std::string _name;
sqlite3 *_db;
std::string _name;
#ifdef OP_SQLITE_USE_LIBSQL
libsql_stmt_t _stmt;
#else
// This shouldn't be de-allocated until sqlite3_finalize is called on it
sqlite3_stmt *_stmt;
#endif
std::shared_ptr<react::CallInvoker> _js_call_invoker;
std::shared_ptr<ThreadPool> _thread_pool;
};

} // namespace opsqlite
7 changes: 4 additions & 3 deletions cpp/SmartHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ std::vector<jsi::PropNameID>
SmartHostObject::getPropertyNames(jsi::Runtime &rt) {
std::vector<jsi::PropNameID> keys;

for (auto field : fields) {
keys.push_back(jsi::PropNameID::forAscii(rt, field.first));
keys.reserve(fields.size());
for (const auto& field : fields) {
keys.emplace_back(jsi::PropNameID::forAscii(rt, field.first));
}

return keys;
Expand All @@ -20,7 +21,7 @@ jsi::Value SmartHostObject::get(jsi::Runtime &rt,
const jsi::PropNameID &propNameID) {
auto name = propNameID.utf8(rt);

for (auto field : fields) {
for (const auto& field : fields) {
auto fieldName = field.first;
if (fieldName == name) {
return to_jsi(rt, field.second);
Expand Down
6 changes: 3 additions & 3 deletions cpp/SmartHostObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace jsi = facebook::jsi;

class JSI_EXPORT SmartHostObject : public jsi::HostObject {
public:
SmartHostObject() {};
SmartHostObject() = default;

std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt);
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override;

jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID);
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propNameID) override;

std::vector<std::pair<std::string, JSVariant>> fields;
};
Expand Down
8 changes: 4 additions & 4 deletions cpp/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ThreadPool::ThreadPool() : done(false) {
// The threads will execute the private member `doWork`. Note that we need
// to pass a reference to the function (namespaced with the class name) as
// the first argument, and the current object as second argument
threads.push_back(std::thread(&ThreadPool::doWork, this));
threads.emplace_back(&ThreadPool::doWork, this);
}
}

Expand All @@ -40,7 +40,7 @@ ThreadPool::~ThreadPool() {

// This function will be called by the server every time there is a request
// that needs to be processed by the thread pool
void ThreadPool::queueWork(std::function<void(void)> task) {
void ThreadPool::queueWork(const std::function<void(void)>& task) {
// Grab the mutex
std::lock_guard<std::mutex> g(workQueueMutex);

Expand All @@ -66,7 +66,7 @@ void ThreadPool::doWork() {
return !workQueue.empty() || done;
});

// If we are shutting down exit witout trying to process more work
// If we are shutting down exit without trying to process more work
if (done) {
break;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ void ThreadPool::restartPool() {
// The threads will execute the private member `doWork`. Note that we need
// to pass a reference to the function (namespaced with the class name) as
// the first argument, and the current object as second argument
threads.push_back(std::thread(&ThreadPool::doWork, this));
threads.emplace_back(&ThreadPool::doWork, this);
}

done = false;
Expand Down
4 changes: 2 additions & 2 deletions cpp/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class ThreadPool {
public:
ThreadPool();
~ThreadPool();
void queueWork(std::function<void(void)> task);
void queueWork(const std::function<void(void)>& task);
void waitFinished();
void restartPool();

private:
unsigned int busy;
unsigned int busy{};
// This condition variable is used for the threads to wait until there is work
// to do
std::condition_variable_any workQueueConditionVariable;
Expand Down
4 changes: 2 additions & 2 deletions cpp/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace opsqlite {

namespace jsi = facebook::jsi;

jsi::Value to_jsi(jsi::Runtime &rt, const JSVariant &value) {
inline jsi::Value to_jsi(jsi::Runtime &rt, const JSVariant &value) {
if (std::holds_alternative<bool>(value)) {
return std::get<bool>(value);
} else if (std::holds_alternative<int>(value)) {
Expand Down Expand Up @@ -74,7 +74,7 @@ jsi::Value to_jsi(jsi::Runtime &rt, const JSVariant &value) {
// value);
}

JSVariant to_variant(jsi::Runtime &rt, const jsi::Value &value) {
inline JSVariant to_variant(jsi::Runtime &rt, const jsi::Value &value) {
if (value.isNull() || value.isUndefined()) {
return JSVariant(nullptr);
} else if (value.isBool()) {
Expand Down

0 comments on commit 4c2b9f8

Please sign in to comment.