Skip to content

Commit 6862983

Browse files
committed
Lint fixing native C/C++ code
1 parent 7b55563 commit 6862983

24 files changed

+824
-1145
lines changed

.clang-format

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BasedOnStyle: Google
2+
SortIncludes: false

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"test": "jest",
2222
"lint": "eslint '{src,tests,benches}/**/*.{js,ts}'",
2323
"lintfix": "eslint '{src,tests,benches}/**/*.{js,ts}' --fix",
24+
"lintnative": "find ./src -type f -regextype posix-extended -regex '.*\\.(c|cc|cpp|h|hh|hpp)' -exec clang-format --dry-run -Werror {} +",
25+
"lintnativefix": "find ./src -type f -regextype posix-extended -regex '.*\\.(c|cc|cpp|h|hh|hpp)' -exec clang-format -i {} +",
2426
"docs": "rimraf ./docs && typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src",
2527
"bench": "rimraf ./benches/results && ts-node -r tsconfig-paths/register ./benches"
2628
},

shell.nix

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mkShell {
55
nativeBuildInputs = [
66
nodejs
77
nodejs.python
8+
clang-tools
89
];
910
# Don't set rpath for native addons
1011
NIX_DONT_SET_RPATH = true;

src/rocksdb/napi/batch.cpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
#define NAPI_VERSION 3
22

33
#include "batch.h"
4+
45
#include <rocksdb/options.h>
56
#include <rocksdb/status.h>
67
#include <rocksdb/slice.h>
78
#include <rocksdb/write_batch.h>
9+
810
#include "database.h"
911

10-
Batch::Batch (Database* database)
11-
: database_(database),
12-
batch_(new rocksdb::WriteBatch()),
13-
hasData_(false) {}
12+
Batch::Batch(Database* database)
13+
: database_(database), batch_(new rocksdb::WriteBatch()), hasData_(false) {}
1414

15-
Batch::~Batch () {
16-
delete batch_;
17-
}
15+
Batch::~Batch() { delete batch_; }
1816

19-
void Batch::Put (rocksdb::Slice key, rocksdb::Slice value) {
17+
void Batch::Put(rocksdb::Slice key, rocksdb::Slice value) {
2018
batch_->Put(key, value);
2119
hasData_ = true;
2220
}
2321

24-
void Batch::Del (rocksdb::Slice key) {
22+
void Batch::Del(rocksdb::Slice key) {
2523
batch_->Delete(key);
2624
hasData_ = true;
2725
}
2826

29-
void Batch::Clear () {
27+
void Batch::Clear() {
3028
batch_->Clear();
3129
hasData_ = false;
3230
}
3331

34-
rocksdb::Status Batch::Write (bool sync) {
32+
rocksdb::Status Batch::Write(bool sync) {
3533
rocksdb::WriteOptions options;
3634
options.sync = sync;
3735
return database_->WriteBatch(options, batch_);

src/rocksdb/napi/batch.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,24 @@
77
#include <rocksdb/status.h>
88
#include <rocksdb/slice.h>
99
#include <rocksdb/write_batch.h>
10+
1011
#include "database.h"
1112

1213
/**
1314
* Owns a WriteBatch.
1415
*/
1516
struct Batch {
16-
Batch (Database* database);
17+
Batch(Database* database);
1718

18-
~Batch ();
19+
~Batch();
1920

20-
void Put (rocksdb::Slice key, rocksdb::Slice value);
21+
void Put(rocksdb::Slice key, rocksdb::Slice value);
2122

22-
void Del (rocksdb::Slice key);
23+
void Del(rocksdb::Slice key);
2324

24-
void Clear ();
25+
void Clear();
2526

26-
rocksdb::Status Write (bool sync);
27+
rocksdb::Status Write(bool sync);
2728

2829
Database* database_;
2930
rocksdb::WriteBatch* batch_;

src/rocksdb/napi/database.cpp

+37-52
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
#define NAPI_VERSION 3
22

33
#include "database.h"
4-
#include <node_api.h>
4+
5+
#include <node/node_api.h>
56
#include <rocksdb/db.h>
67
#include <rocksdb/status.h>
78
#include <rocksdb/slice.h>
89
#include <rocksdb/options.h>
910
#include <rocksdb/utilities/optimistic_transaction_db.h>
11+
1012
#include "worker.h"
1113

12-
Database::Database():
13-
db_(NULL),
14-
currentIteratorId_(0),
15-
currentTransactionId_(0),
16-
pendingCloseWorker_(NULL),
17-
ref_(NULL),
18-
priorityWork_(0) {}
14+
Database::Database()
15+
: db_(NULL),
16+
currentIteratorId_(0),
17+
currentTransactionId_(0),
18+
pendingCloseWorker_(NULL),
19+
ref_(NULL),
20+
priorityWork_(0) {}
1921

2022
Database::~Database() {
2123
if (db_ != NULL) {
@@ -24,107 +26,92 @@ Database::~Database() {
2426
}
2527
}
2628

27-
rocksdb::Status Database::Open (
28-
const rocksdb::Options& options,
29-
const char* location
30-
) {
29+
rocksdb::Status Database::Open(const rocksdb::Options& options,
30+
const char* location) {
3131
return rocksdb::OptimisticTransactionDB::Open(options, location, &db_);
3232
}
3333

34-
void Database::CloseDatabase () {
34+
void Database::CloseDatabase() {
3535
delete db_;
3636
db_ = NULL;
3737
}
3838

39-
rocksdb::Status Database::Put (
40-
const rocksdb::WriteOptions& options,
41-
rocksdb::Slice key,
42-
rocksdb::Slice value
43-
) {
39+
rocksdb::Status Database::Put(const rocksdb::WriteOptions& options,
40+
rocksdb::Slice key, rocksdb::Slice value) {
4441
return db_->Put(options, key, value);
4542
}
4643

47-
rocksdb::Status Database::Get (
48-
const rocksdb::ReadOptions& options,
49-
rocksdb::Slice key,
50-
std::string& value
51-
) {
44+
rocksdb::Status Database::Get(const rocksdb::ReadOptions& options,
45+
rocksdb::Slice key, std::string& value) {
5246
return db_->Get(options, key, &value);
5347
}
5448

55-
rocksdb::Status Database::Del (
56-
const rocksdb::WriteOptions& options,
57-
rocksdb::Slice key
58-
) {
49+
rocksdb::Status Database::Del(const rocksdb::WriteOptions& options,
50+
rocksdb::Slice key) {
5951
return db_->Delete(options, key);
6052
}
6153

62-
rocksdb::Status Database::WriteBatch (
63-
const rocksdb::WriteOptions& options,
64-
rocksdb::WriteBatch* batch
65-
) {
54+
rocksdb::Status Database::WriteBatch(const rocksdb::WriteOptions& options,
55+
rocksdb::WriteBatch* batch) {
6656
return db_->Write(options, batch);
6757
}
6858

69-
uint64_t Database::ApproximateSize (const rocksdb::Range* range) {
59+
uint64_t Database::ApproximateSize(const rocksdb::Range* range) {
7060
uint64_t size = 0;
7161
db_->GetApproximateSizes(range, 1, &size);
7262
return size;
7363
}
7464

75-
void Database::CompactRange (
76-
const rocksdb::Slice* start,
77-
const rocksdb::Slice* end
78-
) {
65+
void Database::CompactRange(const rocksdb::Slice* start,
66+
const rocksdb::Slice* end) {
7967
rocksdb::CompactRangeOptions options;
8068
db_->CompactRange(options, start, end);
8169
}
8270

83-
void Database::GetProperty (const rocksdb::Slice& property, std::string* value) {
71+
void Database::GetProperty(const rocksdb::Slice& property, std::string* value) {
8472
db_->GetProperty(property, value);
8573
}
8674

87-
const rocksdb::Snapshot* Database::NewSnapshot () {
88-
return db_->GetSnapshot();
89-
}
75+
const rocksdb::Snapshot* Database::NewSnapshot() { return db_->GetSnapshot(); }
9076

91-
rocksdb::Iterator* Database::NewIterator (rocksdb::ReadOptions* options) {
77+
rocksdb::Iterator* Database::NewIterator(rocksdb::ReadOptions* options) {
9278
return db_->NewIterator(*options);
9379
}
9480

95-
rocksdb::Transaction* Database::NewTransaction (rocksdb::WriteOptions* options) {
81+
rocksdb::Transaction* Database::NewTransaction(rocksdb::WriteOptions* options) {
9682
return db_->BeginTransaction(*options);
9783
}
9884

99-
void Database::ReleaseSnapshot (const rocksdb::Snapshot* snapshot) {
85+
void Database::ReleaseSnapshot(const rocksdb::Snapshot* snapshot) {
10086
return db_->ReleaseSnapshot(snapshot);
10187
}
10288

103-
void Database::AttachIterator (napi_env env, uint32_t id, Iterator* iterator) {
89+
void Database::AttachIterator(napi_env env, uint32_t id, Iterator* iterator) {
10490
iterators_[id] = iterator;
10591
IncrementPriorityWork(env);
10692
}
10793

108-
void Database::DetachIterator (napi_env env, uint32_t id) {
94+
void Database::DetachIterator(napi_env env, uint32_t id) {
10995
iterators_.erase(id);
11096
DecrementPriorityWork(env);
11197
}
11298

113-
void Database::AttachTransaction (napi_env env, uint32_t id, Transaction* transaction) {
99+
void Database::AttachTransaction(napi_env env, uint32_t id,
100+
Transaction* transaction) {
114101
transactions_[id] = transaction;
115102
IncrementPriorityWork(env);
116103
}
117104

118-
void Database::DetachTransaction (napi_env env, uint32_t id) {
105+
void Database::DetachTransaction(napi_env env, uint32_t id) {
119106
transactions_.erase(id);
120107
DecrementPriorityWork(env);
121108
}
122109

123-
void Database::IncrementPriorityWork (napi_env env) {
110+
void Database::IncrementPriorityWork(napi_env env) {
124111
napi_reference_ref(env, ref_, &priorityWork_);
125112
}
126113

127-
void Database::DecrementPriorityWork (napi_env env) {
114+
void Database::DecrementPriorityWork(napi_env env) {
128115
napi_reference_unref(env, ref_, &priorityWork_);
129116

130117
if (priorityWork_ == 0 && pendingCloseWorker_ != NULL) {
@@ -133,6 +120,4 @@ void Database::DecrementPriorityWork (napi_env env) {
133120
}
134121
}
135122

136-
bool Database::HasPriorityWork () const {
137-
return priorityWork_ > 0;
138-
}
123+
bool Database::HasPriorityWork() const { return priorityWork_ > 0; }

src/rocksdb/napi/database.h

+29-41
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#endif
66

77
#include <map>
8-
#include <node_api.h>
8+
9+
#include <node/node_api.h>
910
#include <rocksdb/db.h>
1011
#include <rocksdb/status.h>
1112
#include <rocksdb/slice.h>
@@ -23,74 +24,61 @@ struct BaseWorker;
2324
* Owns the RocksDB storage, cache, filter policy and iterators.
2425
*/
2526
struct Database {
26-
2727
Database();
2828

2929
~Database();
3030

31-
rocksdb::Status Open (
32-
const rocksdb::Options& options,
33-
const char* location
34-
);
35-
36-
void CloseDatabase ();
31+
rocksdb::Status Open(const rocksdb::Options& options, const char* location);
3732

38-
rocksdb::Status Put (
39-
const rocksdb::WriteOptions& options,
40-
rocksdb::Slice key,
41-
rocksdb::Slice value
42-
);
33+
void CloseDatabase();
4334

44-
rocksdb::Status Get (const rocksdb::ReadOptions& options,
45-
rocksdb::Slice key,
46-
std::string& value);
35+
rocksdb::Status Put(const rocksdb::WriteOptions& options, rocksdb::Slice key,
36+
rocksdb::Slice value);
4737

48-
rocksdb::Status Del (const rocksdb::WriteOptions& options,
49-
rocksdb::Slice key);
38+
rocksdb::Status Get(const rocksdb::ReadOptions& options, rocksdb::Slice key,
39+
std::string& value);
5040

41+
rocksdb::Status Del(const rocksdb::WriteOptions& options, rocksdb::Slice key);
5142

52-
rocksdb::Status WriteBatch (
53-
const rocksdb::WriteOptions& options,
54-
rocksdb::WriteBatch* batch
55-
);
43+
rocksdb::Status WriteBatch(const rocksdb::WriteOptions& options,
44+
rocksdb::WriteBatch* batch);
5645

57-
uint64_t ApproximateSize (const rocksdb::Range* range);
46+
uint64_t ApproximateSize(const rocksdb::Range* range);
5847

59-
void CompactRange (const rocksdb::Slice* start,
60-
const rocksdb::Slice* end);
48+
void CompactRange(const rocksdb::Slice* start, const rocksdb::Slice* end);
6149

62-
void GetProperty (const rocksdb::Slice& property, std::string* value);
50+
void GetProperty(const rocksdb::Slice& property, std::string* value);
6351

64-
const rocksdb::Snapshot* NewSnapshot ();
52+
const rocksdb::Snapshot* NewSnapshot();
6553

66-
rocksdb::Iterator* NewIterator (rocksdb::ReadOptions* options);
54+
rocksdb::Iterator* NewIterator(rocksdb::ReadOptions* options);
6755

68-
rocksdb::Transaction* NewTransaction (rocksdb::WriteOptions* options);
56+
rocksdb::Transaction* NewTransaction(rocksdb::WriteOptions* options);
6957

70-
void ReleaseSnapshot (const rocksdb::Snapshot* snapshot);
58+
void ReleaseSnapshot(const rocksdb::Snapshot* snapshot);
7159

72-
void AttachIterator (napi_env env, uint32_t id, Iterator* iterator);
60+
void AttachIterator(napi_env env, uint32_t id, Iterator* iterator);
7361

74-
void DetachIterator (napi_env env, uint32_t id);
62+
void DetachIterator(napi_env env, uint32_t id);
7563

76-
void AttachTransaction (napi_env env, uint32_t id, Transaction* transaction);
64+
void AttachTransaction(napi_env env, uint32_t id, Transaction* transaction);
7765

78-
void DetachTransaction (napi_env env, uint32_t id);
66+
void DetachTransaction(napi_env env, uint32_t id);
7967

80-
void IncrementPriorityWork (napi_env env);
68+
void IncrementPriorityWork(napi_env env);
8169

82-
void DecrementPriorityWork (napi_env env);
70+
void DecrementPriorityWork(napi_env env);
8371

84-
bool HasPriorityWork () const;
72+
bool HasPriorityWork() const;
8573

8674
rocksdb::OptimisticTransactionDB* db_;
8775
uint32_t currentIteratorId_;
8876
uint32_t currentTransactionId_;
89-
BaseWorker *pendingCloseWorker_;
90-
std::map< uint32_t, Iterator * > iterators_;
91-
std::map< uint32_t, Transaction * > transactions_;
77+
BaseWorker* pendingCloseWorker_;
78+
std::map<uint32_t, Iterator*> iterators_;
79+
std::map<uint32_t, Transaction*> transactions_;
9280
napi_ref ref_;
9381

94-
private:
82+
private:
9583
uint32_t priorityWork_;
9684
};

0 commit comments

Comments
 (0)