From 56d35d4832b0ddd1a48dea5e602eb87619252f8d Mon Sep 17 00:00:00 2001 From: blue Date: Tue, 17 Dec 2024 20:03:48 +0200 Subject: [PATCH] pragma once and minor change in transactions --- CHANGELOG.md | 4 ++++ packaging/Archlinux/PKGBUILD | 2 +- src/base.cpp | 24 +++++++++++------------- src/base.h | 7 ++----- src/cache.h | 5 +---- src/cache.hpp | 5 +---- src/cursor.h | 5 +---- src/cursor.hpp | 7 ++----- src/exceptions.h | 5 +---- src/operators.hpp | 5 +---- src/serializer/serializer.h | 6 ++---- src/serializer/serializer.hpp | 5 +---- src/serializer/serializer_double.hpp | 5 +---- src/serializer/serializer_float.hpp | 8 +------- src/serializer/serializer_int16.hpp | 5 +---- src/serializer/serializer_int32.hpp | 8 +------- src/serializer/serializer_int64.hpp | 8 +------- src/serializer/serializer_int8.hpp | 8 +------- src/serializer/serializer_qbytearray.hpp | 9 +-------- src/serializer/serializer_qstring.hpp | 10 +--------- src/serializer/serializer_stdstring.hpp | 9 +-------- src/serializer/serializer_uint16.hpp | 7 +------ src/serializer/serializer_uint32.hpp | 5 +---- src/serializer/serializer_uint64.hpp | 6 +----- src/serializer/serializer_uint8.hpp | 8 +------- src/storage.h | 5 +---- src/storage.hpp | 5 +---- src/transaction.cpp | 18 ++++++++++++++++++ src/transaction.h | 18 ++++++++++++++++++ 29 files changed, 79 insertions(+), 143 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8194b28..879f52d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +# LMDBAL 0.6.0 (UNRELEASED) +### Improvements +- Less dereferencing + # LMDBAL 0.5.4 (November 30, 2024) ### Improvements - Technical release just to resolve build issues diff --git a/packaging/Archlinux/PKGBUILD b/packaging/Archlinux/PKGBUILD index 38b3e55..c83a648 100644 --- a/packaging/Archlinux/PKGBUILD +++ b/packaging/Archlinux/PKGBUILD @@ -10,7 +10,7 @@ depends=( 'lmdb' ) makedepends=('cmake>=3.16' 'gcc') optdepends=() -source=("lmdbal-$pkgver.tar.gz::https://git.macaw.me/blue/lmdbal/archive/$pkgver.tar.gz") +source=("lmdbal-$pkgver-$pkgrel.tar.gz::https://git.macaw.me/blue/lmdbal/archive/$pkgver.tar.gz") sha256sums=('SKIP') build() { cd "$srcdir/lmdbal" diff --git a/src/base.cpp b/src/base.cpp index 149343b..ef932fd 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -43,7 +43,7 @@ LMDBAL::Base::Base(const QString& _name, uint16_t _mapSize): size(_mapSize), environment(), storages(), - transactions(new Transactions()) + transactions() {} /** @@ -52,8 +52,6 @@ LMDBAL::Base::Base(const QString& _name, uint16_t _mapSize): LMDBAL::Base::~Base() { close(); - delete transactions; - for (const std::pair& pair : storages) delete pair.second; } @@ -68,14 +66,14 @@ LMDBAL::Base::~Base() { */ void LMDBAL::Base::close() { if (opened) { - for (const LMDBAL::TransactionID id : *transactions) + for (const LMDBAL::TransactionID id : transactions) abortTransaction(id, emptyName); for (const std::pair& pair : storages) pair.second->close(); mdb_env_close(environment); - transactions->clear(); + transactions.clear(); opened = false; } } @@ -301,7 +299,7 @@ LMDBAL::TransactionID LMDBAL::Base::beginReadOnlyTransaction(const std::string& throw Closed("beginReadOnlyTransaction", name, storageName); TransactionID txn = beginPrivateReadOnlyTransaction(storageName); - transactions->emplace(txn); + transactions.emplace(txn); for (const std::pair& pair : storages) pair.second->transactionStarted(txn, true); @@ -325,7 +323,7 @@ LMDBAL::TransactionID LMDBAL::Base::beginTransaction(const std::string& storageN throw Closed("beginTransaction", name, storageName); TransactionID txn = beginPrivateTransaction(storageName); - transactions->emplace(txn); + transactions.emplace(txn); for (const std::pair& pair : storages) pair.second->transactionStarted(txn, false); @@ -349,15 +347,15 @@ void LMDBAL::Base::abortTransaction(LMDBAL::TransactionID id, const std::string& if (!opened) throw Closed("abortTransaction", name, storageName); - Transactions::iterator itr = transactions->find(id); - if (itr == transactions->end()) //TODO may be it's a good idea to make an exception class for this + Transactions::iterator itr = transactions.find(id); + if (itr == transactions.end()) //TODO may be it's a good idea to make an exception class for this throw Unknown(name, "unable to abort transaction: transaction was not found", storageName); abortPrivateTransaction(id, storageName); for (const std::pair& pair : storages) pair.second->transactionAborted(id); - transactions->erase(itr); + transactions.erase(itr); } /** @@ -376,15 +374,15 @@ void LMDBAL::Base::commitTransaction(LMDBAL::TransactionID id, const std::string if (!opened) throw Closed("abortTransaction", name, storageName); - Transactions::iterator itr = transactions->find(id); - if (itr == transactions->end()) //TODO may be it's a good idea to make an exception class for this + Transactions::iterator itr = transactions.find(id); + if (itr == transactions.end()) //TODO may be it's a good idea to make an exception class for this throw Unknown(name, "unable to commit transaction: transaction was not found", storageName); commitPrivateTransaction(id, storageName); for (const std::pair& pair : storages) pair.second->transactionCommited(id); - transactions->erase(itr); + transactions.erase(itr); } /** diff --git a/src/base.h b/src/base.h index c99bf21..749683f 100644 --- a/src/base.h +++ b/src/base.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_BASE_H -#define LMDBAL_BASE_H +#pragma once #include #include @@ -106,7 +105,7 @@ private: uint16_t size; /**<\brief lmdb map size in MiB*/ MDB_env* environment; /**<\brief lmdb environment handle*/ Storages storages; /**<\brief Registered storages and caches*/ - Transactions* transactions; /**<\brief Active public transactions*/ + mutable Transactions transactions; /**<\brief Active public transactions*/ inline static const std::string emptyName = ""; /**<\brief Empty string for general fallback purposes*/ }; @@ -215,5 +214,3 @@ template LMDBAL::Cache* LMDBAL::Base::getCache(const std::string& storageName) { return static_cast*>(storages.at(storageName)); } - -#endif //LMDBAL_BASE_H diff --git a/src/cache.h b/src/cache.h index 0883e65..0084984 100644 --- a/src/cache.h +++ b/src/cache.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_CACHE_H -#define LMDBAL_CACHE_H +#pragma once #include #include @@ -134,5 +133,3 @@ protected: } #include "cache.hpp" - -#endif // LMDBAL_CACHE_H diff --git a/src/cache.hpp b/src/cache.hpp index e3c6d60..29af6d0 100644 --- a/src/cache.hpp +++ b/src/cache.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_CACHE_HPP -#define LMDBAL_CACHE_HPP +#pragma once #include "cache.h" #include "exceptions.h" @@ -898,5 +897,3 @@ void LMDBAL::Cache::destroyTransactionEntry(const Entry& entry) const { break; } } - -#endif //LMDBAL_CACHE_HPP diff --git a/src/cursor.h b/src/cursor.h index c3ff362..c77d4e9 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_CURSOR_H -#define LMDBAL_CURSOR_H +#pragma once #include @@ -105,5 +104,3 @@ private: #include "cursor.hpp" - -#endif //LMDBAL_CURSOR_H diff --git a/src/cursor.hpp b/src/cursor.hpp index 519bd41..0e0dc7b 100644 --- a/src/cursor.hpp +++ b/src/cursor.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_CURSOR_HPP -#define LMDBAL_CURSOR_HPP +#pragma once #include "cursor.h" #include @@ -482,7 +481,7 @@ void LMDBAL::Cursor::prev (K& key, V& value) { * \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb */ template -void LMDBAL::Cursor::current (K& key, V& value) const { +void LMDBAL::Cursor::current (K& key, V& value) const { operateCursorRead(key, value, MDB_GET_CURRENT, currentMethodName, currentOperationName); } @@ -657,5 +656,3 @@ void LMDBAL::Cursor::operateCursorRead( else storage->discoveredRecord(key, value, storage->_mdbCursorTxn(cursor)); } - -#endif //LMDBAL_CURSOR_HPP diff --git a/src/exceptions.h b/src/exceptions.h index 58bbea4..6f03bd8 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_EXCEPTIONS_H -#define LMDBAL_EXCEPTIONS_H +#pragma once #include #include @@ -237,5 +236,3 @@ private: }; } - -#endif //LMDBAL_EXCEPTIONS_H diff --git a/src/operators.hpp b/src/operators.hpp index 80353ac..9abb2d0 100644 --- a/src/operators.hpp +++ b/src/operators.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_OPERATORS_HPP -#define LMDBAL_OPERATORS_HPP +#pragma once #include #include @@ -209,5 +208,3 @@ QDataStream& operator >> (QDataStream &in, std::list& container) { return in; } - -#endif //LMDBAL_OPERATORS_HPP diff --git a/src/serializer/serializer.h b/src/serializer/serializer.h index 734ac51..bd7496a 100644 --- a/src/serializer/serializer.h +++ b/src/serializer/serializer.h @@ -16,8 +16,8 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_H -#define LMDBAL_SERIALIZER_H +#pragma once + #include @@ -68,5 +68,3 @@ private: #include "serializer_stdstring.hpp" #include "serializer_qstring.hpp" #include "serializer_qbytearray.hpp" - -#endif // LMDBAL_SERIALIZER_H diff --git a/src/serializer/serializer.hpp b/src/serializer/serializer.hpp index 80f4d90..b3353f5 100644 --- a/src/serializer/serializer.hpp +++ b/src/serializer/serializer.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_HPP -#define LMDBAL_SERIALIZER_HPP +#pragma once #include "serializer.h" @@ -159,5 +158,3 @@ MDB_val LMDBAL::Serializer::getData() { return val; } - -#endif //LMDBAL_SERIALIZER_HPP diff --git a/src/serializer/serializer_double.hpp b/src/serializer/serializer_double.hpp index 4582459..be943b8 100644 --- a/src/serializer/serializer_double.hpp +++ b/src/serializer/serializer_double.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_DOUBLE_HPP -#define LMDBAL_SERIALIZER_DOUBLE_HPP +#pragma once namespace LMDBAL { @@ -53,7 +52,5 @@ private: } -#endif //LMDBAL_SERIALIZER_DOUBLE_HPP - diff --git a/src/serializer/serializer_float.hpp b/src/serializer/serializer_float.hpp index be2c72d..f4b84a9 100644 --- a/src/serializer/serializer_float.hpp +++ b/src/serializer/serializer_float.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_FLOAT_HPP -#define LMDBAL_SERIALIZER_FLOAT_HPP +#pragma once namespace LMDBAL { @@ -52,8 +51,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_FLOAT_HPP - - - diff --git a/src/serializer/serializer_int16.hpp b/src/serializer/serializer_int16.hpp index 17e5ea2..0baaaad 100644 --- a/src/serializer/serializer_int16.hpp +++ b/src/serializer/serializer_int16.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_INT16_HPP -#define LMDBAL_SERIALIZER_INT16_HPP +#pragma once #include @@ -54,5 +53,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_INT16_HPP diff --git a/src/serializer/serializer_int32.hpp b/src/serializer/serializer_int32.hpp index 78405c5..339dfea 100644 --- a/src/serializer/serializer_int32.hpp +++ b/src/serializer/serializer_int32.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_INT32_HPP -#define LMDBAL_SERIALIZER_INT32_HPP +#pragma once #include @@ -54,8 +53,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_INT32_HPP - - - diff --git a/src/serializer/serializer_int64.hpp b/src/serializer/serializer_int64.hpp index 4992ae1..107d102 100644 --- a/src/serializer/serializer_int64.hpp +++ b/src/serializer/serializer_int64.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_INT64_HPP -#define LMDBAL_SERIALIZER_INT64_HPP +#pragma once #include @@ -54,8 +53,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_INT64_HPP - - - diff --git a/src/serializer/serializer_int8.hpp b/src/serializer/serializer_int8.hpp index eafd5c6..6f68f18 100644 --- a/src/serializer/serializer_int8.hpp +++ b/src/serializer/serializer_int8.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_INT8_HPP -#define LMDBAL_SERIALIZER_INT8_HPP +#pragma once #include @@ -54,8 +53,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_INT8_HPP - - - diff --git a/src/serializer/serializer_qbytearray.hpp b/src/serializer/serializer_qbytearray.hpp index 6f1c5d1..daf3027 100644 --- a/src/serializer/serializer_qbytearray.hpp +++ b/src/serializer/serializer_qbytearray.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_QBYTEARRAY_HPP -#define LMDBAL_SERIALIZER_QBYTEARRAY_HPP +#pragma once #include @@ -56,9 +55,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_QBYTEARRAY_HPP - - - - diff --git a/src/serializer/serializer_qstring.hpp b/src/serializer/serializer_qstring.hpp index 1a36fcb..fb9310e 100644 --- a/src/serializer/serializer_qstring.hpp +++ b/src/serializer/serializer_qstring.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_QSTRING_HPP -#define LMDBAL_SERIALIZER_QSTRING_HPP +#pragma once #include #include @@ -56,10 +55,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_QSTRING_HPP - - - - - diff --git a/src/serializer/serializer_stdstring.hpp b/src/serializer/serializer_stdstring.hpp index 416cfd6..1856e8c 100644 --- a/src/serializer/serializer_stdstring.hpp +++ b/src/serializer/serializer_stdstring.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_STDSTRING_HPP -#define LMDBAL_SERIALIZER_STDSTRING_HPP +#pragma once #include @@ -54,9 +53,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_STDSTRING_HPP - - - - diff --git a/src/serializer/serializer_uint16.hpp b/src/serializer/serializer_uint16.hpp index d648695..8284f27 100644 --- a/src/serializer/serializer_uint16.hpp +++ b/src/serializer/serializer_uint16.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_UINT16_HPP -#define LMDBAL_SERIALIZER_UINT16_HPP +#pragma once #include @@ -54,7 +53,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_UINT16_HPP - - diff --git a/src/serializer/serializer_uint32.hpp b/src/serializer/serializer_uint32.hpp index 211f151..83e9d35 100644 --- a/src/serializer/serializer_uint32.hpp +++ b/src/serializer/serializer_uint32.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_UINT32_HPP -#define LMDBAL_SERIALIZER_UINT32_HPP +#pragma once #include @@ -54,5 +53,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_UINT32_HPP diff --git a/src/serializer/serializer_uint64.hpp b/src/serializer/serializer_uint64.hpp index 250ec03..f486082 100644 --- a/src/serializer/serializer_uint64.hpp +++ b/src/serializer/serializer_uint64.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_UINT64_HPP -#define LMDBAL_SERIALIZER_UINT64_HPP +#pragma once #include @@ -54,6 +53,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_UINT64_HPP - diff --git a/src/serializer/serializer_uint8.hpp b/src/serializer/serializer_uint8.hpp index 31daca6..0bc73ab 100644 --- a/src/serializer/serializer_uint8.hpp +++ b/src/serializer/serializer_uint8.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_SERIALIZER_UINT8_HPP -#define LMDBAL_SERIALIZER_UINT8_HPP +#pragma once #include @@ -54,8 +53,3 @@ private: }; } - -#endif //LMDBAL_SERIALIZER_UINT8_HPP - - - diff --git a/src/storage.h b/src/storage.h index 82735a7..c077500 100644 --- a/src/storage.h +++ b/src/storage.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_STORAGE_H -#define LMDBAL_STORAGE_H +#pragma once #include #include @@ -199,5 +198,3 @@ protected: } #include "storage.hpp" - -#endif //LMDBAL_STORAGE_H diff --git a/src/storage.hpp b/src/storage.hpp index 91756b3..e56e91a 100644 --- a/src/storage.hpp +++ b/src/storage.hpp @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef LMDBAL_STORAGE_HPP -#define LMDBAL_STORAGE_HPP +#pragma once #include "storage.h" #include "exceptions.h" @@ -1182,5 +1181,3 @@ template<> inline std::string LMDBAL::iStorage::toString(const std::string& value) { return value; } - -#endif //LMDBAL_STORAGE_HPP diff --git a/src/transaction.cpp b/src/transaction.cpp index 3632ad6..3d7e3c0 100644 --- a/src/transaction.cpp +++ b/src/transaction.cpp @@ -1,3 +1,21 @@ +/* + * LMDB Abstraction Layer. + * Copyright (C) 2023 Yury Gubich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "transaction.h" /** diff --git a/src/transaction.h b/src/transaction.h index 43bb69e..59b6ae9 100644 --- a/src/transaction.h +++ b/src/transaction.h @@ -1,3 +1,21 @@ +/* + * LMDB Abstraction Layer. + * Copyright (C) 2023 Yury Gubich + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #pragma once #include "base.h"