From a19ef9bd1616aaf7997d8caae5cbbfbe23d2f819 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 12 Feb 2018 19:22:32 +0100 Subject: [PATCH] slightly improved --- README.md | 24 ++++++++++++------------ src/entt/entity/sparse_set.hpp | 12 ++++++------ src/entt/entity/view.hpp | 6 ++---- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index a3468bad7..e2cfa08e8 100644 --- a/README.md +++ b/README.md @@ -155,19 +155,19 @@ Dell XPS 13 out of the mid 2014): | Benchmark | EntityX (compile-time) | EnTT | |-----------|-------------|-------------| -| Create 10M entities | 0.1289s | **0.0409s** | -| Destroy 10M entities | **0.0531s** | 0.0546s | -| Standard view, 10M entities, one component | 0.0107s | **1.6e-07s** | -| Standard view, 10M entities, two components | **0.0113s** | 0.0295s | -| Standard view, 10M entities, two components
Half of the entities have all the components | **0.0078s** | 0.0150s | -| Standard view, 10M entities, two components
One of the entities has all the components | 0.0071s | **8.8e-07s** | -| Persistent view, 10M entities, two components | 0.0113s | **5.7e-07s** | -| Standard view, 10M entities, five components | **0.0091s** | 0.0688s | -| Persistent view, 10M entities, five components | 0.0091s | **2.9e-07s** | -| Standard view, 10M entities, ten components | **0.0105s** | 0.1403s | -| Standard view, 10M entities, ten components
Half of the entities have all the components | **0.0090s** | 0.0620s | +| Create 10M entities | 0.1289s | **0.0388s** | +| Destroy 10M entities | **0.0531s** | 0.0828s | +| Standard view, 10M entities, one component | 0.0107s | **7.8e-08s** | +| Standard view, 10M entities, two components | **0.0113s** | 0.0244s | +| Standard view, 10M entities, two components
Half of the entities have all the components | **0.0078s** | 0.0129s | +| Standard view, 10M entities, two components
One of the entities has all the components | 0.0071s | **5.5e-07s** | +| Persistent view, 10M entities, two components | 0.0113s | **1.1e-07s** | +| Standard view, 10M entities, five components | **0.0091s** | 0.0672s | +| Persistent view, 10M entities, five components | 0.0091s | **2.5e-07s** | +| Standard view, 10M entities, ten components | **0.0105s** | 0.1306s | +| Standard view, 10M entities, ten components
Half of the entities have all the components | **0.0090s** | 0.0629s | | Standard view, 10M entities, ten components
One of the entities has all the components | 0.0070s | **1.3e-06s** | -| Persistent view, 10M entities, ten components | 0.0105s | **6.2e-07s** | +| Persistent view, 10M entities, ten components | 0.0105s | **5.0e-07s** | | Sort 150k entities, one component
Arrays are in reverse order | - | **0.0043s** | | Sort 150k entities, enforce permutation
Arrays are in reverse order | - | **0.0006s** | diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index e2b84b3e9..173a90644 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -59,7 +59,7 @@ class SparseSet { struct Iterator final { using value_type = Entity; - Iterator(const std::vector *direct, std::size_t pos) + Iterator(const std::vector &direct, std::size_t pos) : direct{direct}, pos{pos} {} @@ -73,7 +73,7 @@ class SparseSet { } bool operator==(const Iterator &other) const noexcept { - return other.pos == pos && other.direct == direct; + return other.pos == pos; } bool operator!=(const Iterator &other) const noexcept { @@ -81,11 +81,11 @@ class SparseSet { } value_type operator*() const noexcept { - return (*direct)[pos-1]; + return direct[pos-1]; } private: - const std::vector *direct; + const std::vector &direct; std::size_t pos; }; @@ -184,7 +184,7 @@ public: * @return An iterator to the first element of the internal packed array. */ iterator_type begin() const noexcept { - return Iterator{&direct, direct.size()}; + return Iterator{direct, direct.size()}; } /** @@ -201,7 +201,7 @@ public: * internal packed array. */ iterator_type end() const noexcept { - return Iterator{&direct, 0}; + return Iterator{direct, 0}; } /** diff --git a/src/entt/entity/view.hpp b/src/entt/entity/view.hpp index 6192ebfc8..194755a01 100644 --- a/src/entt/entity/view.hpp +++ b/src/entt/entity/view.hpp @@ -358,7 +358,7 @@ class View final { class Iterator { inline bool valid() const noexcept { using accumulator_type = bool[]; - auto entity = *begin; + const auto entity = *begin; bool all = true; accumulator_type accumulator = { all, (all = all && std::get &>(pools).has(entity))... }; (void)accumulator; @@ -377,9 +377,7 @@ class View final { } Iterator & operator++() noexcept { - ++begin; - while(begin != end && !valid()) { ++begin; } - return *this; + return (++begin != end && !valid()) ? ++(*this) : *this; } Iterator operator++(int) noexcept {