From 9dd58224eab3e063daa3ace7d9ef14e43a9b266b Mon Sep 17 00:00:00 2001 From: Jade Lovelace Date: Wed, 4 Dec 2024 15:29:28 -0800 Subject: [PATCH] libexpr: rename misleading type alias Bindings::size_t Calling a custom type size_t is incredibly sneaky and makes all the code around this extremely context dependent. Change-Id: Idae684781f45fe615020d8642f12a656ab2c15ad --- lix/libexpr/attr-set.cc | 4 ++-- lix/libexpr/attr-set.hh | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lix/libexpr/attr-set.cc b/lix/libexpr/attr-set.cc index c6ebde076..1b2d065c0 100644 --- a/lix/libexpr/attr-set.cc +++ b/lix/libexpr/attr-set.cc @@ -17,11 +17,11 @@ Bindings * EvalMemory::allocBindings(size_t capacity) { if (capacity == 0) return &Bindings::EMPTY; - if (capacity > std::numeric_limits::max()) + if (capacity > std::numeric_limits::max()) throw Error("attribute set of size %d is too big", capacity); stats.nrAttrsets++; stats.nrAttrsInAttrsets += capacity; - return new (gcAllocBytes(sizeof(Bindings) + sizeof(Attr) * capacity)) Bindings((Bindings::size_t) capacity); + return new (gcAllocBytes(sizeof(Bindings) + sizeof(Attr) * capacity)) Bindings((Bindings::Size) capacity); } diff --git a/lix/libexpr/attr-set.hh b/lix/libexpr/attr-set.hh index f5ab8dad0..374a10763 100644 --- a/lix/libexpr/attr-set.hh +++ b/lix/libexpr/attr-set.hh @@ -48,20 +48,20 @@ static_assert(sizeof(Attr) == 2 * sizeof(uint32_t) + sizeof(Value *), class Bindings { public: - typedef uint32_t size_t; + using Size = uint32_t; PosIdx pos; static Bindings EMPTY; private: - size_t size_, capacity_; + Size size_, capacity_; Attr attrs[0]; - Bindings(size_t capacity) : size_(0), capacity_(capacity) { } + Bindings(Size capacity) : size_(0), capacity_(capacity) { } Bindings(const Bindings & bindings) = delete; public: - size_t size() const { return size_; } + Size size() const { return size_; } bool empty() const { return !size_; } @@ -92,14 +92,14 @@ public: iterator begin() { return &attrs[0]; } iterator end() { return &attrs[size_]; } - Attr & operator[](size_t pos) + Attr & operator[](Size pos) { return attrs[pos]; } void sort(); - size_t capacity() { return capacity_; } + Size capacity() { return capacity_; } /** * Returns the attributes in lexicographically sorted order. @@ -108,7 +108,7 @@ public: { std::vector res; res.reserve(size_); - for (size_t n = 0; n < size_; n++) + for (Size n = 0; n < size_; n++) res.emplace_back(&attrs[n]); std::sort(res.begin(), res.end(), [&](const Attr * a, const Attr * b) { std::string_view sa = symbols[a->name], sb = symbols[b->name];