From: Amos Jeffries <> Date: Wed, 12 Apr 2017 00:00:22 +0000 (+1200) Subject: Cleanup: remove redundant IntRange class from StoreMeta.cc X-Git-Tag: M-staged-PR71~199 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21dfc374d05c5403076c27f49fbed60918b73073;p=thirdparty%2Fsquid.git Cleanup: remove redundant IntRange class from StoreMeta.cc 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. --- diff --git a/src/HttpHeaderRange.h b/src/HttpHeaderRange.h index 85e2b93a66..d8daf14e8b 100644 --- a/src/HttpHeaderRange.h +++ b/src/HttpHeaderRange.h @@ -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 diff --git a/src/Store.h b/src/Store.h index d20ea4d6dd..c5ffeb6370 100644 --- a/src/Store.h +++ b/src/Store.h @@ -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" diff --git a/src/StoreIOBuffer.h b/src/StoreIOBuffer.h index 7f715f788e..9adf9ba21a 100644 --- a/src/StoreIOBuffer.h +++ b/src/StoreIOBuffer.h @@ -9,8 +9,8 @@ #ifndef SQUID_STOREIOBUFFER_H #define SQUID_STOREIOBUFFER_H +#include "base/Range.h" #include "MemBuf.h" -#include "Range.h" class StoreIOBuffer { diff --git a/src/StoreMeta.cc b/src/StoreMeta.cc index 4b83958bad..0216f9e5e9 100644 --- a/src/StoreMeta.cc +++ b/src/StoreMeta.cc @@ -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 TlvValidLengths = Range(StoreMeta::MinimumTLVLength, StoreMeta::MaximumTLVLength); + if (!TlvValidLengths.contains(aLength)) { + debugs(20, DBG_CRITICAL, MYNAME << ": insane length (" << aLength << ")!"); return false; } diff --git a/src/acl/IntRange.h b/src/acl/IntRange.h index a571422a53..a7dbb8be53 100644 --- a/src/acl/IntRange.h +++ b/src/acl/IntRange.h @@ -10,7 +10,7 @@ #define SQUID_ACLINTRANGE_H #include "acl/Data.h" -#include "Range.h" +#include "base/Range.h" #include diff --git a/src/base/Makefile.am b/src/base/Makefile.am index 5dc8fbcfe5..449d497d0c 100644 --- a/src/base/Makefile.am +++ b/src/base/Makefile.am @@ -32,6 +32,7 @@ libbase_la_SOURCES = \ LruMap.h \ Packable.h \ PackableStream.h \ + Range.h \ RegexPattern.cc \ RegexPattern.h \ RunnersRegistry.cc \ diff --git a/include/Range.h b/src/base/Range.h similarity index 86% rename from include/Range.h rename to src/base/Range.h index fc6a6902df..157e6ce765 100644 --- a/include/Range.h +++ b/src/base/Range.h @@ -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::intersection (Range const &rhs) const return result; } +template +bool +Range::contains(C const &value) const { + assert(start <= end); + return (start <= value && value <= end); +} + template S Range::size() const diff --git a/src/mem_node.h b/src/mem_node.h index 2767d28c95..bf1d82bc8d 100644 --- a/src/mem_node.h +++ b/src/mem_node.h @@ -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 diff --git a/src/snmp/Pdu.h b/src/snmp/Pdu.h index ac70a7b3ad..a960212531 100644 --- a/src/snmp/Pdu.h +++ b/src/snmp/Pdu.h @@ -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 diff --git a/src/snmp/Var.h b/src/snmp/Var.h index 2c65577b02..0d333bf0ba 100644 --- a/src/snmp/Var.h +++ b/src/snmp/Var.h @@ -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 diff --git a/src/stmem.h b/src/stmem.h index b35137a349..9d28135f5f 100644 --- a/src/stmem.h +++ b/src/stmem.h @@ -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;