diff --git a/include/mbgl/tile/tile_id.hpp b/include/mbgl/tile/tile_id.hpp index c9c9ca7e72d..340dfe41773 100644 --- a/include/mbgl/tile/tile_id.hpp +++ b/include/mbgl/tile/tile_id.hpp @@ -23,13 +23,13 @@ class UnwrappedTileID; // there. z is never larger than the source's maxzoom class CanonicalTileID { public: - CanonicalTileID(uint8_t z, uint32_t x, uint32_t y); - bool operator==(const CanonicalTileID&) const; - bool operator!=(const CanonicalTileID&) const; - bool operator<(const CanonicalTileID&) const; - bool isChildOf(const CanonicalTileID&) const; - CanonicalTileID scaledTo(uint8_t z) const; - std::array children() const; + CanonicalTileID(uint8_t z, uint32_t x, uint32_t y) noexcept; + bool operator==(const CanonicalTileID&) const noexcept; + bool operator!=(const CanonicalTileID&) const noexcept; + bool operator<(const CanonicalTileID&) const noexcept; + bool isChildOf(const CanonicalTileID&) const noexcept; + CanonicalTileID scaledTo(uint8_t z) const noexcept; + std::array children() const noexcept; uint8_t z; uint32_t x; @@ -47,19 +47,19 @@ std::string toString(const CanonicalTileID&); // the class OverscaledTileID { public: - OverscaledTileID(uint8_t overscaledZ, int16_t wrap, CanonicalTileID); - OverscaledTileID(uint8_t overscaledZ, int16_t wrap, uint8_t z, uint32_t x, uint32_t y); - OverscaledTileID(uint8_t z, uint32_t x, uint32_t y); - explicit OverscaledTileID(const CanonicalTileID&); - explicit OverscaledTileID(CanonicalTileID&&); - bool operator==(const OverscaledTileID&) const; - bool operator!=(const OverscaledTileID&) const; - bool operator<(const OverscaledTileID&) const; - bool isChildOf(const OverscaledTileID&) const; - uint32_t overscaleFactor() const; - OverscaledTileID scaledTo(uint8_t z) const; - UnwrappedTileID toUnwrapped() const; - OverscaledTileID unwrapTo(int16_t wrap) const; + OverscaledTileID(uint8_t overscaledZ, int16_t wrap, CanonicalTileID) noexcept; + OverscaledTileID(uint8_t overscaledZ, int16_t wrap, uint8_t z, uint32_t x, uint32_t y) noexcept; + OverscaledTileID(uint8_t z, uint32_t x, uint32_t y) noexcept; + explicit OverscaledTileID(const CanonicalTileID&) noexcept; + explicit OverscaledTileID(CanonicalTileID&&) noexcept; + bool operator==(const OverscaledTileID&) const noexcept; + bool operator!=(const OverscaledTileID&) const noexcept; + bool operator<(const OverscaledTileID&) const noexcept; + bool isChildOf(const OverscaledTileID&) const noexcept; + uint32_t overscaleFactor() const noexcept; + OverscaledTileID scaledTo(uint8_t z) const noexcept; + UnwrappedTileID toUnwrapped() const noexcept; + OverscaledTileID unwrapTo(int16_t wrap) const noexcept; uint8_t overscaledZ; int16_t wrap; @@ -77,16 +77,16 @@ std::string toString(const OverscaledTileID&); // rendered at (= calc the matrix) z is never larger than the source's maxzoom class UnwrappedTileID { public: - UnwrappedTileID(uint8_t z, int64_t x, int64_t y); - UnwrappedTileID(int16_t wrap, CanonicalTileID); - bool operator==(const UnwrappedTileID&) const; - bool operator!=(const UnwrappedTileID&) const; - bool operator<(const UnwrappedTileID&) const; - bool isChildOf(const UnwrappedTileID&) const; - std::array children() const; - OverscaledTileID overscaleTo(uint8_t z) const; - float pixelsToTileUnits(float pixelValue, float zoom) const; - UnwrappedTileID unwrapTo(int16_t wrap) const; + UnwrappedTileID(uint8_t z, int64_t x, int64_t y) noexcept; + UnwrappedTileID(int16_t wrap, CanonicalTileID) noexcept; + bool operator==(const UnwrappedTileID&) const noexcept; + bool operator!=(const UnwrappedTileID&) const noexcept; + bool operator<(const UnwrappedTileID&) const noexcept; + bool isChildOf(const UnwrappedTileID&) const noexcept; + std::array children() const noexcept; + OverscaledTileID overscaleTo(uint8_t z) const noexcept; + float pixelsToTileUnits(float pixelValue, float zoom) const noexcept; + UnwrappedTileID unwrapTo(int16_t wrap) const noexcept; int16_t wrap; CanonicalTileID canonical; @@ -97,7 +97,7 @@ namespace util { std::string toString(const UnwrappedTileID&); } // namespace util -inline CanonicalTileID::CanonicalTileID(uint8_t z_, uint32_t x_, uint32_t y_) +inline CanonicalTileID::CanonicalTileID(uint8_t z_, uint32_t x_, uint32_t y_) noexcept : z(z_), x(x_), y(y_) { @@ -106,24 +106,24 @@ inline CanonicalTileID::CanonicalTileID(uint8_t z_, uint32_t x_, uint32_t y_) assert(y < (1ull << z)); } -inline bool CanonicalTileID::operator==(const CanonicalTileID& rhs) const { +inline bool CanonicalTileID::operator==(const CanonicalTileID& rhs) const noexcept { return z == rhs.z && x == rhs.x && y == rhs.y; } -inline bool CanonicalTileID::operator!=(const CanonicalTileID& rhs) const { +inline bool CanonicalTileID::operator!=(const CanonicalTileID& rhs) const noexcept { return z != rhs.z || x != rhs.x || y != rhs.y; } -inline bool CanonicalTileID::operator<(const CanonicalTileID& rhs) const { +inline bool CanonicalTileID::operator<(const CanonicalTileID& rhs) const noexcept { return std::tie(z, x, y) < std::tie(rhs.z, rhs.x, rhs.y); } -inline bool CanonicalTileID::isChildOf(const CanonicalTileID& parent) const { +inline bool CanonicalTileID::isChildOf(const CanonicalTileID& parent) const noexcept { // We're first testing for z == 0, to avoid a 32 bit shift, which is undefined. return parent.z == 0 || (parent.z < z && parent.x == (x >> (z - parent.z)) && parent.y == (y >> (z - parent.z))); } -inline CanonicalTileID CanonicalTileID::scaledTo(uint8_t targetZ) const { +inline CanonicalTileID CanonicalTileID::scaledTo(uint8_t targetZ) const noexcept { if (targetZ <= z) { return {targetZ, x >> (z - targetZ), y >> (z - targetZ)}; // parent or same } else { @@ -131,7 +131,7 @@ inline CanonicalTileID CanonicalTileID::scaledTo(uint8_t targetZ) const { } } -inline std::array CanonicalTileID::children() const { +inline std::array CanonicalTileID::children() const noexcept { const uint8_t childZ = z + 1; const uint32_t childX = x * 2; const uint32_t childY = y * 2; @@ -143,103 +143,104 @@ inline std::array CanonicalTileID::children() const { }}; } -inline OverscaledTileID::OverscaledTileID(uint8_t overscaledZ_, int16_t wrap_, CanonicalTileID canonical_) +inline OverscaledTileID::OverscaledTileID(uint8_t overscaledZ_, int16_t wrap_, CanonicalTileID canonical_) noexcept : overscaledZ(overscaledZ_), wrap(wrap_), canonical(canonical_) { assert(overscaledZ >= canonical.z); } -inline OverscaledTileID::OverscaledTileID(uint8_t overscaledZ_, int16_t wrap_, uint8_t z, uint32_t x, uint32_t y) +inline OverscaledTileID::OverscaledTileID( + uint8_t overscaledZ_, int16_t wrap_, uint8_t z, uint32_t x, uint32_t y) noexcept : overscaledZ(overscaledZ_), wrap(wrap_), canonical(z, x, y) { assert(overscaledZ >= canonical.z); } -inline OverscaledTileID::OverscaledTileID(uint8_t z, uint32_t x, uint32_t y) +inline OverscaledTileID::OverscaledTileID(uint8_t z, uint32_t x, uint32_t y) noexcept : overscaledZ(z), wrap(0), canonical(z, x, y) {} -inline OverscaledTileID::OverscaledTileID(const CanonicalTileID& canonical_) +inline OverscaledTileID::OverscaledTileID(const CanonicalTileID& canonical_) noexcept : overscaledZ(canonical_.z), wrap(0), canonical(canonical_) { assert(overscaledZ >= canonical.z); } -inline OverscaledTileID::OverscaledTileID(CanonicalTileID&& canonical_) +inline OverscaledTileID::OverscaledTileID(CanonicalTileID&& canonical_) noexcept : overscaledZ(canonical_.z), wrap(0), canonical(std::forward(canonical_)) { assert(overscaledZ >= canonical.z); } -inline bool OverscaledTileID::operator==(const OverscaledTileID& rhs) const { +inline bool OverscaledTileID::operator==(const OverscaledTileID& rhs) const noexcept { return overscaledZ == rhs.overscaledZ && wrap == rhs.wrap && canonical == rhs.canonical; } -inline bool OverscaledTileID::operator!=(const OverscaledTileID& rhs) const { +inline bool OverscaledTileID::operator!=(const OverscaledTileID& rhs) const noexcept { return overscaledZ != rhs.overscaledZ || wrap != rhs.wrap || canonical != rhs.canonical; } -inline bool OverscaledTileID::operator<(const OverscaledTileID& rhs) const { +inline bool OverscaledTileID::operator<(const OverscaledTileID& rhs) const noexcept { return std::tie(overscaledZ, wrap, canonical) < std::tie(rhs.overscaledZ, rhs.wrap, rhs.canonical); } -inline uint32_t OverscaledTileID::overscaleFactor() const { +inline uint32_t OverscaledTileID::overscaleFactor() const noexcept { return 1u << (overscaledZ - canonical.z); } -inline bool OverscaledTileID::isChildOf(const OverscaledTileID& rhs) const { +inline bool OverscaledTileID::isChildOf(const OverscaledTileID& rhs) const noexcept { return wrap == rhs.wrap && overscaledZ > rhs.overscaledZ && (canonical == rhs.canonical || canonical.isChildOf(rhs.canonical)); } -inline OverscaledTileID OverscaledTileID::scaledTo(uint8_t z) const { +inline OverscaledTileID OverscaledTileID::scaledTo(uint8_t z) const noexcept { return {z, wrap, z >= canonical.z ? canonical : canonical.scaledTo(z)}; } -inline UnwrappedTileID OverscaledTileID::toUnwrapped() const { +inline UnwrappedTileID OverscaledTileID::toUnwrapped() const noexcept { return {wrap, canonical}; } -inline OverscaledTileID OverscaledTileID::unwrapTo(int16_t newWrap) const { +inline OverscaledTileID OverscaledTileID::unwrapTo(int16_t newWrap) const noexcept { return {overscaledZ, newWrap, canonical}; } -inline UnwrappedTileID::UnwrappedTileID(uint8_t z_, int64_t x_, int64_t y_) +inline UnwrappedTileID::UnwrappedTileID(uint8_t z_, int64_t x_, int64_t y_) noexcept : wrap(static_cast((x_ < 0 ? x_ - (1ll << z_) + 1 : x_) / (1ll << z_))), canonical(z_, static_cast(x_ - wrap * (1ll << z_)), y_ < 0 ? 0 : std::min(static_cast(y_), static_cast(1ull << z_) - 1)) {} -inline UnwrappedTileID::UnwrappedTileID(int16_t wrap_, CanonicalTileID canonical_) +inline UnwrappedTileID::UnwrappedTileID(int16_t wrap_, CanonicalTileID canonical_) noexcept : wrap(wrap_), canonical(canonical_) {} -inline bool UnwrappedTileID::operator==(const UnwrappedTileID& rhs) const { +inline bool UnwrappedTileID::operator==(const UnwrappedTileID& rhs) const noexcept { return wrap == rhs.wrap && canonical == rhs.canonical; } -inline bool UnwrappedTileID::operator!=(const UnwrappedTileID& rhs) const { +inline bool UnwrappedTileID::operator!=(const UnwrappedTileID& rhs) const noexcept { return wrap != rhs.wrap || canonical != rhs.canonical; } -inline bool UnwrappedTileID::operator<(const UnwrappedTileID& rhs) const { +inline bool UnwrappedTileID::operator<(const UnwrappedTileID& rhs) const noexcept { return std::tie(wrap, canonical) < std::tie(rhs.wrap, rhs.canonical); } -inline UnwrappedTileID UnwrappedTileID::unwrapTo(int16_t newWrap) const { +inline UnwrappedTileID UnwrappedTileID::unwrapTo(int16_t newWrap) const noexcept { return {newWrap, canonical}; } -inline bool UnwrappedTileID::isChildOf(const UnwrappedTileID& parent) const { +inline bool UnwrappedTileID::isChildOf(const UnwrappedTileID& parent) const noexcept { return wrap == parent.wrap && canonical.isChildOf(parent.canonical); } -inline std::array UnwrappedTileID::children() const { +inline std::array UnwrappedTileID::children() const noexcept { const uint8_t childZ = canonical.z + 1; const uint32_t childX = canonical.x * 2; const uint32_t childY = canonical.y * 2; @@ -251,12 +252,12 @@ inline std::array UnwrappedTileID::children() const { }}; } -inline OverscaledTileID UnwrappedTileID::overscaleTo(const uint8_t overscaledZ) const { +inline OverscaledTileID UnwrappedTileID::overscaleTo(const uint8_t overscaledZ) const noexcept { assert(overscaledZ >= canonical.z); return {overscaledZ, wrap, canonical}; } -inline float UnwrappedTileID::pixelsToTileUnits(const float pixelValue, const float zoom) const { +inline float UnwrappedTileID::pixelsToTileUnits(const float pixelValue, const float zoom) const noexcept { return pixelValue * (static_cast(util::EXTENT) / (static_cast(util::tileSize_D) * std::pow(2.f, zoom - canonical.z))); } @@ -267,17 +268,17 @@ namespace std { template <> struct hash { - size_t operator()(const mbgl::CanonicalTileID& id) const; + size_t operator()(const mbgl::CanonicalTileID& id) const noexcept; }; template <> struct hash { - size_t operator()(const mbgl::UnwrappedTileID& id) const; + size_t operator()(const mbgl::UnwrappedTileID& id) const noexcept; }; template <> struct hash { - size_t operator()(const mbgl::OverscaledTileID& id) const; + size_t operator()(const mbgl::OverscaledTileID& id) const noexcept; }; } // namespace std diff --git a/src/mbgl/tile/tile_id_hash.cpp b/src/mbgl/tile/tile_id_hash.cpp index d4a7d880772..d09caac8abe 100644 --- a/src/mbgl/tile/tile_id_hash.cpp +++ b/src/mbgl/tile/tile_id_hash.cpp @@ -3,7 +3,7 @@ namespace std { -size_t hash::operator()(const mbgl::CanonicalTileID& id) const { +size_t hash::operator()(const mbgl::CanonicalTileID& id) const noexcept { std::size_t seed = 0; mbgl::util::hash_combine(seed, id.x); mbgl::util::hash_combine(seed, id.y); @@ -11,14 +11,14 @@ size_t hash::operator()(const mbgl::CanonicalTileID& id) return seed; } -size_t hash::operator()(const mbgl::UnwrappedTileID& id) const { +size_t hash::operator()(const mbgl::UnwrappedTileID& id) const noexcept { std::size_t seed = 0; mbgl::util::hash_combine(seed, std::hash{}(id.canonical)); mbgl::util::hash_combine(seed, id.wrap); return seed; } -size_t hash::operator()(const mbgl::OverscaledTileID& id) const { +size_t hash::operator()(const mbgl::OverscaledTileID& id) const noexcept { std::size_t seed = 0; mbgl::util::hash_combine(seed, std::hash{}(id.canonical)); mbgl::util::hash_combine(seed, id.overscaledZ); diff --git a/src/mbgl/util/hash.hpp b/src/mbgl/util/hash.hpp index 299d018dd7b..e49f73cf355 100644 --- a/src/mbgl/util/hash.hpp +++ b/src/mbgl/util/hash.hpp @@ -9,12 +9,12 @@ namespace mbgl { namespace util { template -void hash_combine(std::size_t& seed, const T& v) { +void hash_combine(std::size_t& seed, const T& v) noexcept { seed ^= std::hash()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } template -std::size_t hash(Args&&... args) { +std::size_t hash(Args&&... args) noexcept { std::size_t seed = 0; ignore({(hash_combine(seed, args), 0)...}); return seed;