From 8be0d57d2422fe495909df24998834a2680e887f Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Thu, 20 Jul 2023 18:13:07 +0200 Subject: [PATCH] VariantPoolList: reduce the size of `capacity_` and `count_` --- src/ArduinoJson/Memory/VariantPoolList.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ArduinoJson/Memory/VariantPoolList.hpp b/src/ArduinoJson/Memory/VariantPoolList.hpp index 0e7cf9f6..f7f145d9 100644 --- a/src/ArduinoJson/Memory/VariantPoolList.hpp +++ b/src/ArduinoJson/Memory/VariantPoolList.hpp @@ -9,6 +9,8 @@ ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE +using PoolCount = SlotId; + class VariantPoolList { public: VariantPoolList() = default; @@ -63,7 +65,7 @@ class VariantPoolList { void clear(Allocator* allocator) { if (!pools_) return; - for (size_t i = 0; i < count_; i++) + for (PoolCount i = 0; i < count_; i++) pools_[i].destroy(allocator); allocator->deallocate(pools_); pools_ = nullptr; @@ -73,7 +75,7 @@ class VariantPoolList { SlotCount usage() const { SlotCount total = 0; - for (size_t i = 0; i < count_; i++) + for (PoolCount i = 0; i < count_; i++) total = SlotCount(total + pools_[i].usage()); return total; } @@ -112,9 +114,9 @@ class VariantPoolList { bool increaseCapacity(Allocator* allocator) { void* newPools; - size_t newCapacity; + PoolCount newCapacity; if (pools_) { - newCapacity = capacity_ * 2; + newCapacity = PoolCount(capacity_ * 2); newPools = allocator->reallocate(pools_, newCapacity * sizeof(VariantPool)); } else { @@ -129,8 +131,8 @@ class VariantPoolList { } VariantPool* pools_ = nullptr; - size_t count_ = 0; - size_t capacity_ = 0; + PoolCount count_ = 0; + PoolCount capacity_ = 0; SlotId freeList_ = NULL_SLOT; };