@@ -14745,7 +14745,9 @@ namespace sqlite_orm {
1474514745 return _control.db;
1474614746 }
1474714747
14748- // optional fast path: if connection is already open, just increment counter;
14748+ // required fast path: if connection is already open, just increment counter;
14749+ // it is required otherwise 'retain if open' would be useless;
14750+ // with respect to performance,
1474914751 // this can make a difference while a transaction is active where all things happen in memory only;
1475014752 // it makes a difference if the `_didOpenDb` callback has a lot of work to do.
1475114753 if (int currentCount = _control.retainCount.load(std::memory_order_acquire)) {
@@ -14761,7 +14763,7 @@ namespace sqlite_orm {
1476114763 } while (currentCount > 0);
1476214764 }
1476314765 // test for recursion from the same thread
14764- else {
14766+ else /*currentCount==0*/ {
1476514767 const std::thread::id threadId = _control.initializingThreadId.load(std::memory_order_acquire);
1476614768 if (threadId != std::thread::id{} && std::this_thread::get_id() == threadId)
1476714769 SQLITE_ORM_CPP_UNLIKELY {
@@ -14773,6 +14775,7 @@ namespace sqlite_orm {
1477314775 }
1477414776
1477514777 sqlite3* retain() {
14778+ // optional fast path: if connection is already open, just increment counter;
1477614779 if (sqlite3* db = retain_if_open()) {
1477714780 return db;
1477814781 }
@@ -14850,6 +14853,9 @@ namespace sqlite_orm {
1485014853 const std::function<void(sqlite3* db)> _didOpenDb;
1485114854 };
1485214855
14856+ /*
14857+ Acquires a database connection upon construction and releases it upon destruction.
14858+ */
1485314859 struct connection_ref {
1485414860 connection_ref(connection_holder& holder) : holder{&holder}, db{holder.retain()} {}
1485514861
@@ -14878,6 +14884,9 @@ namespace sqlite_orm {
1487814884 sqlite3* db;
1487914885 };
1488014886
14887+ /*
14888+ Increases the reference count of an existing open connection upon construction and releases it upon destruction.
14889+ */
1488114890 struct connection_ptr {
1488214891 connection_ptr(connection_holder& holder) : holder{&holder}, db{holder.retain_if_open()} {}
1488314892
0 commit comments