Skip to content

Commit 352a7bc

Browse files
committed
fix: remove nested conditional
1 parent 6aec131 commit 352a7bc

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

binding.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,7 @@ leveldb::Status threadsafe_open(const leveldb::Options &options,
637637
std::unique_lock<std::mutex> lock(handles_mutex);
638638

639639
auto it = db_handles.find(db_instance.location_);
640-
if (it != db_handles.end()) {
641-
if (!allow_multi_threading) {
642-
return leveldb::Status::IOError("lock " + db_instance.location_, "already held by process");
643-
}
640+
if (it != db_handles.end() && allow_multi_threading) {
644641
// Database already opened for this location
645642
++(it->second.open_handle_count);
646643
db_instance.db_ = it->second.db;
@@ -664,13 +661,13 @@ leveldb::Status threadsafe_close(Database &db_instance) {
664661
db_instance.db_ = NULL; // ensure db_ pointer is nullified in Database instance
665662

666663
auto it = db_handles.find(db_instance.location_);
667-
if (it != db_handles.end()) {
668-
if (--(it->second.open_handle_count) == 0) {
669-
delete it->second.db;
670-
db_handles.erase(it);
671-
}
672-
} else {
664+
if (it == db_handles.end()) {
673665
return leveldb::Status::NotFound("Database handle not found for the given location");
666+
}
667+
668+
if (--(it->second.open_handle_count) == 0) {
669+
delete it->second.db;
670+
db_handles.erase(it);
674671
}
675672

676673
return leveldb::Status::OK();

0 commit comments

Comments
 (0)