]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: remove redundant IntRange class from StoreMeta.cc
authorAmos Jeffries <>
Wed, 12 Apr 2017 00:00:22 +0000 (12:00 +1200)
committerAmos Jeffries <>
Wed, 12 Apr 2017 00:00:22 +0000 (12:00 +1200)
Use the Range<> template we have for generic ranges.

Move the Range.h template definitio to src/base/. It is only used by
code in src/.

Also, include a small performance improvements for StoreMeta::validLength().
Storing the valid TLV length limits in a static instead of generating a
new object instance on each call.

src/HttpHeaderRange.h
src/Store.h
src/StoreIOBuffer.h
src/StoreMeta.cc
src/acl/IntRange.h
src/base/Makefile.am
src/base/Range.h [moved from include/Range.h with 86% similarity]
src/mem_node.h
src/snmp/Pdu.h
src/snmp/Var.h
src/stmem.h

index 85e2b93a66e7f09856ad28b26ab066095f947b42..d8daf14e8ba045a31069416ce91b12fb9485a970 100644 (file)
@@ -9,8 +9,8 @@
 #ifndef SQUID_HTTPHEADERRANGE_H
 #define SQUID_HTTPHEADERRANGE_H
 
+#include "base/Range.h"
 #include "mem/forward.h"
-#include "Range.h"
 #include "SquidString.h"
 
 #include <vector>
index d20ea4d6dde33d41c936cb95ec07b38de22044aa..c5ffeb63706bd038d654ecfe3d4abb0184b9f576 100644 (file)
@@ -10,6 +10,7 @@
 #define SQUID_STORE_H
 
 #include "base/Packable.h"
+#include "base/Range.h"
 #include "base/RefCount.h"
 #include "comm/forward.h"
 #include "CommRead.h"
@@ -18,7 +19,6 @@
 #include "http/RequestMethod.h"
 #include "HttpReply.h"
 #include "MemObject.h"
-#include "Range.h"
 #include "RemovalPolicy.h"
 #include "store/Controller.h"
 #include "store/forward.h"
index 7f715f788e93e126d6ecb81b4953d8cb45b43d8a..9adf9ba21a3898a4e8179f12c278a011c71a1902 100644 (file)
@@ -9,8 +9,8 @@
 #ifndef SQUID_STOREIOBUFFER_H
 #define SQUID_STOREIOBUFFER_H
 
+#include "base/Range.h"
 #include "MemBuf.h"
-#include "Range.h"
 
 class StoreIOBuffer
 {
index 4b83958bade8466766e17ca6cde2898a20f27efb..0216f9e5e979285a20a7f35d2019600599b2a070 100644 (file)
@@ -9,6 +9,7 @@
 /* DEBUG: section 20    Storage Manager Swapfile Metadata */
 
 #include "squid.h"
+#include "base/Range.h"
 #include "MemObject.h"
 #include "Store.h"
 #include "StoreMeta.h"
@@ -48,38 +49,15 @@ StoreMeta::validType(char type)
     return true;
 }
 
-class IntRange
-{
-
-public:
-    IntRange (int minimum, int maximum) : _min (minimum), _max (maximum) {
-        if (_min > _max) {
-            int temp = _min;
-            _min = _max;
-            _max = temp;
-        }
-    }
-
-    bool includes (int anInt) const {
-        if (anInt < _min || anInt > _max)
-            return false;
-
-        return true;
-    }
-
-private:
-    int _min;
-    int _max;
-};
-
 const int StoreMeta::MinimumTLVLength = 0;
 const int StoreMeta::MaximumTLVLength = 1 << 16;
 
 bool
 StoreMeta::validLength(int aLength) const
 {
-    if (!IntRange (MinimumTLVLength, MaximumTLVLength).includes(aLength)) {
-        debugs(20, DBG_CRITICAL, "storeSwapMetaUnpack: insane length (" << aLength << ")!");
+    static const Range<int> TlvValidLengths = Range<int>(StoreMeta::MinimumTLVLength, StoreMeta::MaximumTLVLength);
+    if (!TlvValidLengths.contains(aLength)) {
+        debugs(20, DBG_CRITICAL, MYNAME << ": insane length (" << aLength << ")!");
         return false;
     }
 
index a571422a538cc405dce0f591306b3f8d5b8701f8..a7dbb8be53d0f045ce399bc265de89784e17161b 100644 (file)
@@ -10,7 +10,7 @@
 #define SQUID_ACLINTRANGE_H
 
 #include "acl/Data.h"
-#include "Range.h"
+#include "base/Range.h"
 
 #include <list>
 
index 5dc8fbcfe5366a7598e47367f7a01a404dda6ff7..449d497d0c27bf7bbebd5076e15e46ea991c66fb 100644 (file)
@@ -32,6 +32,7 @@ libbase_la_SOURCES = \
        LruMap.h \
        Packable.h \
        PackableStream.h \
+       Range.h \
        RegexPattern.cc \
        RegexPattern.h \
        RunnersRegistry.cc \
similarity index 86%
rename from include/Range.h
rename to src/base/Range.h
index fc6a6902dfe534948fcdff48078e92992c43e0c6..157e6ce765bcba8b56bf900aa561f2c63b956d95 100644 (file)
@@ -24,6 +24,7 @@ public:
     C start;
     C end;
     Range intersection (Range const &) const;
+    bool contains(C const &) const;
     S size() const;
 };
 
@@ -48,6 +49,13 @@ Range<C, S>::intersection (Range const &rhs) const
     return result;
 }
 
+template<class C, class S>
+bool
+Range<C, S>::contains(C const &value) const {
+    assert(start <= end);
+    return (start <= value && value <= end);
+}
+
 template<class C, class S>
 S
 Range<C, S>::size() const
index 2767d28c95f95ca97a34dd32bae6ddaa91f4de6a..bf1d82bc8dd7cc5890b579ed9ccc46e3f30d8759 100644 (file)
@@ -9,9 +9,9 @@
 #ifndef SQUID_MEM_NODE_H
 #define SQUID_MEM_NODE_H
 
+#include "base/Range.h"
 #include "defines.h"
 #include "mem/forward.h"
-#include "Range.h"
 #include "StoreIOBuffer.h"
 
 class mem_node
index ac70a7b3adab01a1293eaef1e281d399efbafacc..a9602125311ee824ed9e22431fccd2ac9d59e1c2 100644 (file)
@@ -11,8 +11,8 @@
 #ifndef SQUID_SNMPX_PDU_H
 #define SQUID_SNMPX_PDU_H
 
+#include "base/Range.h"
 #include "ipc/forward.h"
-#include "Range.h"
 #include "snmp.h"
 
 namespace Snmp
index 2c65577b0239057e9a9c7af835e3cf276780d8f1..0d333bf0ba6287784011cc75272ce8cc4f2462f9 100644 (file)
@@ -11,8 +11,8 @@
 #ifndef SQUID_SNMPX_VAR_H
 #define SQUID_SNMPX_VAR_H
 
+#include "base/Range.h"
 #include "ipc/forward.h"
-#include "Range.h"
 #include "snmp_vars.h"
 
 namespace Snmp
index b35137a3495df7191575681fa284060aecf13b01..9d28135f5fa11a07a8fa0a8f37bcb3fdee3f27bf 100644 (file)
@@ -9,7 +9,7 @@
 #ifndef SQUID_STMEM_H
 #define SQUID_STMEM_H
 
-#include "Range.h"
+#include "base/Range.h"
 #include "splay.h"
 
 class mem_node;