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 +- src/argument_parser.cpp | 18 +++++++++--------- src/argument_parser.hpp | 12 ++++++------ src/bootstrap.cpp | 2 +- src/bootstrap.hpp | 2 +- src/conversion.cpp | 2 +- src/conversion.hpp | 4 ++-- src/engine/data/bounds.cpp | 18 +++++++++--------- src/engine/data/bounds.hpp | 16 +++++++++------- src/engine/data/vector2.cpp | 22 ---------------------- src/engine/data/vector2.hpp | 26 +++++++++++++++++++++----- src/engine/engine.cpp | 2 +- src/engine/engine.hpp | 3 ++- src/engine/graphics/scene.cpp | 2 +- src/engine/graphics/string_matrix.cpp | 12 ++++++------ src/engine/graphics/string_matrix.hpp | 12 ++++++------ src/engine/user/cursor.cpp | 16 ++++++++-------- src/engine/user/cursor.hpp | 6 +++--- src/engine/user/input.cpp | 10 +++++----- src/engine/user/input.hpp | 12 ++++++------ src/game/game.cpp | 2 +- src/game/game.hpp | 4 ++-- src/game_of_life.cpp | 2 +- src/input_actions.cpp | 4 ++-- src/input_actions.hpp | 6 +++--- src/interfaces/argument_parser.hpp | 6 +++--- src/interfaces/input.hpp | 12 ++++++------ src/interfaces/matrix.hpp | 12 ++++++------ src/interfaces/observable.hpp | 8 ++++---- src/interfaces/randomization.hpp | 8 ++++---- src/randomization/generator.cpp | 5 +++-- src/randomization/generator.hpp | 5 +++-- src/randomization/seed_generator.cpp | 5 +++-- src/randomization/seed_generator.hpp | 5 +++-- 44 files changed, 170 insertions(+), 168 deletions(-) (limited to 'src') 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); } diff --git a/src/argument_parser.cpp b/src/argument_parser.cpp index 16945f7..94c6a4a 100644 --- a/src/argument_parser.cpp +++ b/src/argument_parser.cpp @@ -9,7 +9,7 @@ namespace { -void optarg_error(char arg, const std::string_view &error) +void optarg_error(char arg, const std::string_view &error) noexcept { std::cout << "Error: Invalid option argument for -" << arg << ". " << error << std::endl; @@ -19,7 +19,7 @@ void optarg_error(char arg, const std::string_view &error) /** * Returns the current optarg as a string view. */ -std::string_view get_str_optarg() +std::string_view get_str_optarg() noexcept { return std::string_view(optarg); } @@ -30,7 +30,7 @@ std::string_view get_str_optarg() * @param arg The current command-line argument character * @param check_zero Whether or not to make sure that the result is not zero */ -uint32_t get_uint_optarg(char arg, bool check_zero = false) +uint32_t get_uint_optarg(char arg, bool check_zero = false) noexcept { auto conversion_result = str_to_uint(get_str_optarg()); @@ -44,16 +44,16 @@ uint32_t get_uint_optarg(char arg, bool check_zero = false) } // namespace ArgumentParser::ArgumentParser( - IRandomNumberGeneratorFactory random_number_generator_factory) + IRandomNumberGeneratorFactory random_number_generator_factory) noexcept : _random_number_generator_factory(random_number_generator_factory) { } -ParsedArguments -ArgumentParser::parse(const std::vector