]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Simplify DelayId composite position management (#2126)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Tue, 22 Jul 2025 23:42:46 +0000 (23:42 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Thu, 24 Jul 2025 23:43:32 +0000 (23:43 +0000)
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
src/DelayId.h

index 9f97ed6758d73f85c094ceafee8ceb64a4a476aa..17b70ef8b44a2156ee915f577c6347dc3644b8ef 100644 (file)
 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
index 66036101f5872acfe555e0b18fd8435020b50962..d9cb49639a058c460f9ab170a6cd823927dc5e4a 100644 (file)
@@ -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