Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
snej committed Nov 20, 2024
1 parent 96cda1a commit 69007df
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion C/Cpp_include/c4Database.hh
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ struct C4Database
db->endTransaction(false);
}

bool isActive() const noexcept {return _db != nullptr;}
bool isActive() const noexcept { return _db != nullptr; }

~Transaction() {
if ( _db ) _db->endTransaction(false);
Expand Down
6 changes: 2 additions & 4 deletions C/tests/c4Test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ ostream& operator<<(ostream& out, C4Error error) {

ERROR_INFO::~ERROR_INFO() {
if ( _error->code && OnMainThread() ) {
if (OnMainThread())
UNSCOPED_INFO(*_error);
if ( OnMainThread() ) UNSCOPED_INFO(*_error);
else
std::cerr << "ERROR_INFO: " << *_error << '\n';
}
Expand All @@ -91,8 +90,7 @@ WITH_ERROR::~WITH_ERROR() {
// Unfortunately it's too late to use UNSCOPED_INFO; since WITH_ERROR is used inside the
// CHECK/REQUIRE macro, by the time it's destructed Catch has already registered the error.
// But we can tell Catch to warn about it, which will show up below its failure message.
if (OnMainThread())
WARN(*_error);
if ( OnMainThread() ) WARN(*_error);
else
std::cerr << "WITH_ERROR: " << *_error << '\n';
}
Expand Down
2 changes: 1 addition & 1 deletion LiteCore/Storage/DataFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ namespace litecore {
ExclusiveTransaction::ExclusiveTransaction(DataFile* db) : ExclusiveTransaction(db, true) {}

ExclusiveTransaction::ExclusiveTransaction(DataFile* db, bool active) : _db(*db), _active(false) {
if (active && !_db.options().writeable)
if ( active && !_db.options().writeable )
error::_throw(error::NotWriteable, "Transaction on read-only database");
_db.beginTransactionScope(this);
if ( active ) {
Expand Down
6 changes: 2 additions & 4 deletions LiteCore/Support/DatabasePool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,8 @@ namespace litecore {
_cond.notify_all(); // wake up waiting `borrow` and `close` calls
}


#pragma mark - BORROWED DATABASE:


BorrowedDatabase& BorrowedDatabase::operator=(BorrowedDatabase&& b) noexcept {
_return();
_db = std::move(b._db);
Expand All @@ -226,8 +224,8 @@ namespace litecore {
}

BorrowedCollection::BorrowedCollection(BorrowedDatabase&& bdb, C4CollectionSpec const& spec)
: _bdb(std::move(bdb)), _collection(_bdb ? _bdb->getCollection(spec) : nullptr) {
if (_bdb && !_collection) error::_throw(error::NotFound, "no such collection");
: _bdb(std::move(bdb)), _collection(_bdb ? _bdb->getCollection(spec) : nullptr) {
if ( _bdb && !_collection ) error::_throw(error::NotFound, "no such collection");
}


Expand Down
17 changes: 9 additions & 8 deletions LiteCore/Support/DatabasePool.hh
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ namespace litecore {

protected:
friend class DatabasePool;
BorrowedDatabase(BorrowedDatabase const&) = delete;
BorrowedDatabase(BorrowedDatabase const&) = delete;
BorrowedDatabase& operator=(BorrowedDatabase const&) = delete;

// used by DatabasePool::borrow methods
Expand Down Expand Up @@ -264,21 +264,22 @@ namespace litecore {
Remember to call `commit`!
@note Using this avoids the footgun `C4Database::Transaction t(pool.borrowWriteable());`
which unintentionally returns the database to the pool immediately! */
class DatabasePool::Transaction : private BorrowedDatabase, public C4Database::Transaction {
public:
class DatabasePool::Transaction
: private BorrowedDatabase
, public C4Database::Transaction {
public:
explicit Transaction(DatabasePool& pool)
: BorrowedDatabase(pool.borrowWriteable())
, C4Database::Transaction(db()) {}
: BorrowedDatabase(pool.borrowWriteable()), C4Database::Transaction(db()) {}

C4Database* db() const noexcept LIFETIMEBOUND {return get();}
C4Database* db() const noexcept LIFETIMEBOUND { return get(); }
};

inline DatabasePool::Transaction DatabasePool::transaction() {return Transaction(*this);}
inline DatabasePool::Transaction DatabasePool::transaction() { return Transaction(*this); }

inline auto DatabasePool::inTransaction(auto fn) {
Transaction txn(*this);
fn(txn.db());
if (txn.isActive()) txn.commit();
if ( txn.isActive() ) txn.commit();
}


Expand Down

0 comments on commit 69007df

Please sign in to comment.