diff options
author | HampusM <hampus@hampusmat.com> | 2022-03-14 18:02:18 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-06-13 17:56:56 +0200 |
commit | dc6222611ad14a33f642396558ba84ecba9d6605 (patch) | |
tree | d759020233b66be62c5539209a03842d283b67a9 /src/engine/data | |
parent | dbab54ebf134b6ab2cf719d7c26a191fbffeed34 (diff) |
perf: add noexcept almost everywhere
Diffstat (limited to 'src/engine/data')
-rw-r--r-- | src/engine/data/bounds.cpp | 18 | ||||
-rw-r--r-- | src/engine/data/bounds.hpp | 16 | ||||
-rw-r--r-- | src/engine/data/vector2.cpp | 22 | ||||
-rw-r--r-- | src/engine/data/vector2.hpp | 26 |
4 files changed, 39 insertions, 43 deletions
diff --git a/src/engine/data/bounds.cpp b/src/engine/data/bounds.cpp index 41b6dc0..fdf8c6b 100644 --- a/src/engine/data/bounds.cpp +++ b/src/engine/data/bounds.cpp @@ -1,48 +1,48 @@ #include "bounds.hpp" -Bounds::Bounds(const BoundsOptions &options) +Bounds::Bounds(const BoundsOptions &options) noexcept : _width(options.width), _height(options.height) { } -uint32_t Bounds::get_width() const noexcept +Bounds::Value Bounds::get_width() const noexcept { return _width; } -void Bounds::set_width(uint32_t width) noexcept +void Bounds::set_width(Bounds::Value width) noexcept { _width = width; } -uint32_t Bounds::get_height() const noexcept +Bounds::Value Bounds::get_height() const noexcept { return _height; } -void Bounds::set_height(uint32_t height) noexcept +void Bounds::set_height(Bounds::Value height) noexcept { _height = height; } CoordsValidation Bounds::validate_coords(const Vector2 &coords) const noexcept { - if (static_cast<uint32_t>(coords.get_x()) >= _width) + if (static_cast<Bounds::Value>(coords.get_x()) >= _width) { return CoordsValidation::X_HIGH; } - if (static_cast<uint32_t>(coords.get_x()) <= 0) + if (static_cast<Bounds::Value>(coords.get_x()) <= 0) { return CoordsValidation::X_LOW; } - if (static_cast<uint32_t>(coords.get_y()) >= _height) + if (static_cast<Bounds::Value>(coords.get_y()) >= _height) { return CoordsValidation::Y_HIGH; } - if (static_cast<uint32_t>(coords.get_y()) <= 0) + if (static_cast<Bounds::Value>(coords.get_y()) <= 0) { return CoordsValidation::Y_LOW; } diff --git a/src/engine/data/bounds.hpp b/src/engine/data/bounds.hpp index 9b72f59..4a29158 100644 --- a/src/engine/data/bounds.hpp +++ b/src/engine/data/bounds.hpp @@ -22,15 +22,17 @@ struct BoundsOptions class Bounds { public: - explicit Bounds(const BoundsOptions &options); + using Value = uint32_t; - [[nodiscard]] uint32_t get_width() const noexcept; + explicit Bounds(const BoundsOptions &options) noexcept; - void set_width(uint32_t width) noexcept; + [[nodiscard]] Value get_width() const noexcept; - [[nodiscard]] uint32_t get_height() const noexcept; + void set_width(Value width) noexcept; - void set_height(uint32_t height) noexcept; + [[nodiscard]] Value get_height() const noexcept; + + void set_height(Value height) noexcept; [[nodiscard]] CoordsValidation validate_coords(const Vector2 &coords) const noexcept; @@ -39,6 +41,6 @@ public: const Bounds &operator-=(const Bounds &bounds) noexcept; private: - uint32_t _width = 0U; - uint32_t _height = 0U; + Value _width = 0U; + Value _height = 0U; }; diff --git a/src/engine/data/vector2.cpp b/src/engine/data/vector2.cpp index 04cc42e..dba745f 100644 --- a/src/engine/data/vector2.cpp +++ b/src/engine/data/vector2.cpp @@ -2,8 +2,6 @@ #include "util/hash.hpp" -Vector2::Vector2(const Vector2Options &options) : _x(options.x), _y(options.y) {} - Vector2::Value Vector2::get_x() const noexcept { return _x; @@ -71,26 +69,6 @@ bool Vector2::operator==(const Vector2 &vector2) const noexcept return _x == vector2._x && _y == vector2._y; } -Vector2 Vector2::up() noexcept -{ - return Vector2({.x = 0, .y = -1}); -} - -Vector2 Vector2::down() noexcept -{ - return Vector2({.x = 0, .y = 1}); -} - -Vector2 Vector2::left() noexcept -{ - return Vector2({.x = -1, .y = 0}); -} - -Vector2 Vector2::right() noexcept -{ - return Vector2({.x = 1, .y = 0}); -} - std::size_t Vector2Hasher::operator()(const Vector2 &vector2) const noexcept { std::size_t result_hash = 0; diff --git a/src/engine/data/vector2.hpp b/src/engine/data/vector2.hpp index e835e65..868394a 100644 --- a/src/engine/data/vector2.hpp +++ b/src/engine/data/vector2.hpp @@ -17,7 +17,10 @@ class Vector2 public: using Value = int32_t; - explicit Vector2(const Vector2Options &options); + constexpr explicit Vector2(const Vector2Options &options) noexcept + : _x(options.x), _y(options.y) + { + } [[nodiscard]] Value get_x() const noexcept; @@ -41,22 +44,35 @@ public: /** * Returns Vector2({.x = 0, .y = -1}) */ - static Vector2 up() noexcept; + static constexpr Vector2 up() noexcept + { + return Vector2({.x = 0, .y = -1}); + } /** * Returns Vector2({.x = 0, .y = 1}) */ - static Vector2 down() noexcept; + static constexpr Vector2 down() noexcept + { + return Vector2({.x = 0, .y = 1}); + } /** * Returns Vector2({.x = -1, .y = 0}) */ - static Vector2 left() noexcept; + static constexpr Vector2 left() noexcept + { + + return Vector2({.x = -1, .y = 0}); + } /** * Returns Vector2({.x = 1, .y = 0}) */ - static Vector2 right() noexcept; + static constexpr Vector2 right() noexcept + { + return Vector2({.x = 1, .y = 0}); + } private: Value _x; |