From 0d7760d2fcf304357d980c5f2dc531a8b62d400c Mon Sep 17 00:00:00 2001 From: Eduard Bagdasaryan Date: Tue, 22 Jul 2025 23:42:46 +0000 Subject: [PATCH] Simplify DelayId composite position management (#2126) Moved DelayId::compositeId initialization to the constructor and removed its setter and getters as unused. Simplified DelayId methods by using "pool and compositeId are either both set or both unset" invariant that is now upheld by the two corresponding class constructors. --- src/DelayId.cc | 36 ++++++++++-------------------------- src/DelayId.h | 5 +---- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/DelayId.cc b/src/DelayId.cc index 9f97ed6758..17b70ef8b4 100644 --- a/src/DelayId.cc +++ b/src/DelayId.cc @@ -28,21 +28,17 @@ DelayId::DelayId () : pool_ (0), compositeId(nullptr), markedAsNoDelay(false) {} -DelayId::DelayId (unsigned short aPool) : - pool_ (aPool), compositeId (nullptr), markedAsNoDelay (false) +DelayId::DelayId(const unsigned short aPool, const DelayIdComposite::Pointer &aCompositeId): + pool_(aPool), compositeId(aCompositeId), markedAsNoDelay(false) { + assert(pool_); + assert(compositeId); debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u"); } DelayId::~DelayId () {} -void -DelayId::compositePosition(const DelayIdComposite::Pointer &newPosition) -{ - compositeId = newPosition; -} - unsigned short DelayId::pool() const { @@ -60,7 +56,7 @@ DelayId::operator == (DelayId const &rhs) const DelayId::operator bool() const { - return (pool_ || compositeId.getRaw()) && !markedAsNoDelay; + return compositeId && !markedAsNoDelay; } /* create a delay Id for a given request */ @@ -98,14 +94,11 @@ DelayId::DelayClient(ClientHttpRequest * http, HttpReply *reply) ch.src_addr = r->client_addr; if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck().allowed()) { - - DelayId result (pool + 1); CompositePoolNode::CompositeSelectionDetails details(ch.src_addr, StringToSBuf(r->tag)); #if USE_AUTH details.user = r->auth_user_request; #endif - result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details)); - return result; + return DelayId(pool + 1, DelayPools::delay_data[pool].theComposite()->id(details)); } } @@ -125,18 +118,12 @@ DelayId::setNoDelay(bool const newValue) int DelayId::bytesWanted(int minimum, int maximum) const { - /* unlimited */ + const auto maxBytes = max(minimum, maximum); if (! (*this)) - return max(minimum, maximum); - - /* limited */ - int nbytes = max(minimum, maximum); + return maxBytes; - if (compositeId != nullptr) - nbytes = compositeId->bytesWanted(minimum, nbytes); - - return nbytes; + return compositeId->bytesWanted(minimum, maxBytes); } /* @@ -150,10 +137,7 @@ DelayId::bytesIn(int qty) if (! (*this)) return; - assert ((unsigned short)(pool() - 1) != 0xFFFF); - - if (compositeId != nullptr) - compositeId->bytesIn(qty); + compositeId->bytesIn(qty); } void diff --git a/src/DelayId.h b/src/DelayId.h index 66036101f5..d9cb49639a 100644 --- a/src/DelayId.h +++ b/src/DelayId.h @@ -24,12 +24,9 @@ class DelayId public: static DelayId DelayClient(ClientHttpRequest *, HttpReply *reply = nullptr); DelayId (); - DelayId (unsigned short); + DelayId(unsigned short, const DelayIdComposite::Pointer &); ~DelayId (); unsigned short pool() const; - DelayIdComposite::Pointer compositePosition(); - DelayIdComposite::Pointer const compositePosition() const; - void compositePosition(const DelayIdComposite::Pointer &); bool operator == (DelayId const &rhs) const; /// Whether we may delay reading. This operator is meant to be used as an -- 2.47.3