From dc6222611ad14a33f642396558ba84ecba9d6605 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 14 Mar 2022 18:02:18 +0100 Subject: perf: add noexcept almost everywhere --- src/DI/auto_wirable.hpp | 6 +++--- src/DI/auto_wirable.tpp | 4 ++-- src/DI/container.hpp | 14 +++++++------- src/DI/container.tpp | 13 +++++++------ src/DI/function_wrapper.hpp | 2 +- src/DI/function_wrapper.tpp | 2 +- src/DI/interfaces/wrapper.hpp | 4 ++-- src/DI/object_type.cpp | 2 +- src/DI/object_type.hpp | 6 +++--- src/DI/object_wrapper.hpp | 2 +- src/DI/object_wrapper.tpp | 2 +- 11 files changed, 29 insertions(+), 28 deletions(-) (limited to 'src/DI') diff --git a/src/DI/auto_wirable.hpp b/src/DI/auto_wirable.hpp index 13d252e..a903242 100644 --- a/src/DI/auto_wirable.hpp +++ b/src/DI/auto_wirable.hpp @@ -8,21 +8,21 @@ class IGenericAutoWirable { public: - virtual ~IGenericAutoWirable() = default; + virtual ~IGenericAutoWirable() noexcept = default; }; template class IAutoWirable : public IGenericAutoWirable { public: - static Interface resolve(); + static Interface resolve() noexcept; }; template class AutoWirable : public IAutoWirable { public: - static std::shared_ptr resolve(const Container &container); + static std::shared_ptr resolve(const Container &container) noexcept; }; #include "auto_wirable.tpp" diff --git a/src/DI/auto_wirable.tpp b/src/DI/auto_wirable.tpp index 6c0d111..a99d82b 100644 --- a/src/DI/auto_wirable.tpp +++ b/src/DI/auto_wirable.tpp @@ -3,8 +3,8 @@ #include "auto_wirable.hpp" template -std::shared_ptr -AutoWirable::resolve(const Container &container) +std::shared_ptr AutoWirable::resolve( + const Container &container) noexcept { return std::make_shared(container.get()...); } diff --git a/src/DI/container.hpp b/src/DI/container.hpp index 93722b6..974780a 100644 --- a/src/DI/container.hpp +++ b/src/DI/container.hpp @@ -14,13 +14,13 @@ template class BindingBuilder { public: - explicit BindingBuilder(Container *container); + explicit BindingBuilder(Container *container) noexcept; template >> - void to(); + void to() noexcept; - void to_factory(Interface func); + void to_factory(Interface func) noexcept; private: Container *_container; @@ -29,16 +29,16 @@ private: class Container { public: - Container() = default; + Container() noexcept = default; template - BindingBuilder bind(); + BindingBuilder bind() noexcept; template >> - std::shared_ptr get() const; + std::shared_ptr get() const noexcept; template >> - Interface get() const; + Interface get() const noexcept; std::unordered_map, ObjectTypeHasher> bindings; diff --git a/src/DI/container.tpp b/src/DI/container.tpp index e5bf7f7..ed7f34f 100644 --- a/src/DI/container.tpp +++ b/src/DI/container.tpp @@ -8,13 +8,14 @@ #include template -BindingBuilder::BindingBuilder(Container *container) : _container(container) +BindingBuilder::BindingBuilder(Container *container) noexcept + : _container(container) { } template template -void BindingBuilder::to() +void BindingBuilder::to() noexcept { _container->bindings.emplace( ObjectType(), @@ -23,7 +24,7 @@ void BindingBuilder::to() } template -void BindingBuilder::to_factory(Interface func) +void BindingBuilder::to_factory(Interface func) noexcept { _container->bindings.emplace(ObjectType(), std::dynamic_pointer_cast( @@ -31,13 +32,13 @@ void BindingBuilder::to_factory(Interface func) } template -BindingBuilder Container::bind() +BindingBuilder Container::bind() noexcept { return BindingBuilder(this); } template -std::shared_ptr Container::get() const +std::shared_ptr Container::get() const noexcept { ObjectType interface_type; @@ -56,7 +57,7 @@ std::shared_ptr Container::get() const } template -Interface Container::get() const +Interface Container::get() const noexcept { auto wrapper = std::dynamic_pointer_cast>( bindings.at(ObjectType())); diff --git a/src/DI/function_wrapper.hpp b/src/DI/function_wrapper.hpp index f135e7f..e6468f2 100644 --- a/src/DI/function_wrapper.hpp +++ b/src/DI/function_wrapper.hpp @@ -11,7 +11,7 @@ class FunctionWrapper : public IWrapper public: explicit FunctionWrapper(Interface func) noexcept; - [[nodiscard]] Interface get() const override; + [[nodiscard]] Interface get() const noexcept override; private: const Interface _func; diff --git a/src/DI/function_wrapper.tpp b/src/DI/function_wrapper.tpp index 920c7f2..540a7aa 100644 --- a/src/DI/function_wrapper.tpp +++ b/src/DI/function_wrapper.tpp @@ -8,7 +8,7 @@ FunctionWrapper::FunctionWrapper(Interface func) noexcept : _func(fun } template -Interface FunctionWrapper::get() const +Interface FunctionWrapper::get() const noexcept { return _func; } diff --git a/src/DI/interfaces/wrapper.hpp b/src/DI/interfaces/wrapper.hpp index 3cc75a0..cde555f 100644 --- a/src/DI/interfaces/wrapper.hpp +++ b/src/DI/interfaces/wrapper.hpp @@ -6,12 +6,12 @@ class IGenericWrapper { public: - virtual ~IGenericWrapper() = default; + virtual ~IGenericWrapper() noexcept = default; }; template class IWrapper : public IGenericWrapper { public: - [[nodiscard]] virtual Interface get() const = 0; + [[nodiscard]] virtual Interface get() const noexcept = 0; }; diff --git a/src/DI/object_type.cpp b/src/DI/object_type.cpp index f6004cb..008c4a4 100644 --- a/src/DI/object_type.cpp +++ b/src/DI/object_type.cpp @@ -20,7 +20,7 @@ std::string_view BaseObjectType::name() const noexcept return std::string_view(_type_info.name()); } -std::size_t ObjectTypeHasher::operator()(const BaseObjectType &object_type) const +std::size_t ObjectTypeHasher::operator()(const BaseObjectType &object_type) const noexcept { return object_type.hash(); } diff --git a/src/DI/object_type.hpp b/src/DI/object_type.hpp index 3910c03..84bb287 100644 --- a/src/DI/object_type.hpp +++ b/src/DI/object_type.hpp @@ -22,17 +22,17 @@ template class ObjectType : public BaseObjectType { public: - ObjectType() : BaseObjectType(typeid(Object)) {} + ObjectType() noexcept : BaseObjectType(typeid(Object)) {} }; class IObjectTypeHasher { public: - virtual std::size_t operator()(const BaseObjectType &object_type) const = 0; + virtual std::size_t operator()(const BaseObjectType &object_type) const noexcept = 0; }; class ObjectTypeHasher : public IObjectTypeHasher { public: - std::size_t operator()(const BaseObjectType &object_type) const override; + std::size_t operator()(const BaseObjectType &object_type) const noexcept override; }; diff --git a/src/DI/object_wrapper.hpp b/src/DI/object_wrapper.hpp index 6fe3997..4aee9af 100644 --- a/src/DI/object_wrapper.hpp +++ b/src/DI/object_wrapper.hpp @@ -11,7 +11,7 @@ class ObjectWrapper : public IWrapper> public: explicit ObjectWrapper(const Container &container) noexcept : _container(container) {} - [[nodiscard]] std::shared_ptr get() const override; + [[nodiscard]] std::shared_ptr get() const noexcept override; private: const Container &_container; diff --git a/src/DI/object_wrapper.tpp b/src/DI/object_wrapper.tpp index 7efefc4..bbb7bee 100644 --- a/src/DI/object_wrapper.tpp +++ b/src/DI/object_wrapper.tpp @@ -3,7 +3,7 @@ #include "object_wrapper.hpp" template -std::shared_ptr ObjectWrapper::get() const +std::shared_ptr ObjectWrapper::get() const noexcept { return ObjectImpl::resolve(_container); } -- cgit v1.2.3-18-g5258