HttpHeader::HttpHeader() : owner (hoNone), len (0), conflictingContentLength_(false)
{
+ entries.reserve(32);
httpHeaderMaskInit(&mask, 0);
}
{
assert(anOwner > hoNone && anOwner < hoEnd);
debugs(55, 7, "init-ing hdr: " << this << " owner: " << owner);
+ entries.reserve(32);
httpHeaderMaskInit(&mask, 0);
}
HttpHeader::HttpHeader(const HttpHeader &other): owner(other.owner), len(other.len), conflictingContentLength_(false)
{
+ entries.reserve(other.entries.capacity());
httpHeaderMaskInit(&mask, 0);
update(&other); // will update the mask as well
}
#include "http/RegisteredHeaders.h"
/* because we pass a spec by value */
#include "HttpHeaderMask.h"
-#include "mem/forward.h"
+#include "mem/PoolingAllocator.h"
#include "sbuf/forward.h"
#include "SquidString.h"
inline bool chunked() const; ///< whether message uses chunked Transfer-Encoding
/* protected, do not use these, use interface functions instead */
- std::vector<HttpHeaderEntry *> entries; /**< parsed fields in raw format */
+ std::vector<HttpHeaderEntry*, PoolingAllocator<HttpHeaderEntry*> > entries; /**< parsed fields in raw format */
HttpHeaderMask mask; /**< bit set <=> entry present */
http_hdr_owner_type owner; /**< request or reply */
int len; /**< length when packed, not counting terminating null-byte */
AllocatorProxy.cc \
AllocatorProxy.h \
forward.h \
- old_api.cc \
Meter.h \
+ old_api.cc \
Pool.cc \
Pool.h \
PoolChunked.cc \
PoolChunked.h \
+ PoolingAllocator.h \
PoolMalloc.cc \
PoolMalloc.h
--- /dev/null
+/*
++ * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
++ *
++ * Squid software is distributed under GPLv2+ license and includes
++ * contributions from numerous individuals and organizations.
++ * Please see the COPYING and CONTRIBUTORS files for details.
++ */
+
+#ifndef SQUID_MEM_POOLINGALLOCATOR_H
+#define SQUID_MEM_POOLINGALLOCATOR_H
+
+#include "mem/forward.h"
+
+/// STL Allocator that uses Squid memory pools for memory management
+template <class Value>
+class PoolingAllocator
+{
+public:
+ /* STL Allocator API */
+ using value_type = Value;
+ PoolingAllocator() noexcept {}
+ template <class Other> PoolingAllocator(const PoolingAllocator<Other> &) noexcept {}
+ value_type *allocate(std::size_t n) { return static_cast<value_type*>(memAllocRigid(n*sizeof(value_type))); }
+ void deallocate(value_type *vp, std::size_t n) noexcept { memFreeRigid(vp, n*sizeof(value_type)); }
+};
+
+template <class L, class R>
+inline bool
+operator ==(const PoolingAllocator<L>&, const PoolingAllocator<R>&) noexcept
+{
+ return true;
+}
+
+template <class L, class R>
+inline bool
+operator !=(const PoolingAllocator<L> &l, const PoolingAllocator<R> &r) noexcept
+{
+ return !(l == r);
+}
+
+#endif /* SQUID_MEM_POOLINGALLOCATOR_H */
+
void *memAllocate(mem_type);
void *memAllocString(size_t net_size, size_t * gross_size);
void *memAllocBuf(size_t net_size, size_t * gross_size);
+void *memAllocRigid(size_t net_size);
void *memReallocBuf(void *buf, size_t net_size, size_t * gross_size);
/// Free a element allocated by memAllocate()
void memFree(void *, int type);
void memFreeString(size_t size, void *);
void memFreeBuf(size_t size, void *);
+void memFreeRigid(void *, size_t net_size);
FREE *memFreeBufFunc(size_t size);
int memInUse(mem_type);
void memDataInit(mem_type, const char *, size_t, int, bool doZero = true);
return xcalloc(1, net_size);
}
+void *
+memAllocRigid(size_t net_size)
+{
+ // TODO: Use memAllocString() instead (after it stops zeroing memory).
+
+ if (const auto pool = memFindStringPool(net_size, true)) {
+ ++StrCountMeter;
+ StrVolumeMeter += pool->objectSize();
+ return pool->alloc();
+ }
+
+ ++StrCountMeter;
+ StrVolumeMeter += net_size;
+ return xmalloc(net_size);
+}
+
size_t
memStringCount()
{
StrVolumeMeter -= size;
}
+void
+memFreeRigid(void *buf, size_t net_size)
+{
+ // TODO: Use memFreeString() instead (after removing fuzzy=false pool search).
+
+ if (const auto pool = memFindStringPool(net_size, true)) {
+ pool->freeOne(buf);
+ StrVolumeMeter -= pool->objectSize();
+ --StrCountMeter;
+ return;
+ }
+
+ xfree(buf);
+ StrVolumeMeter -= net_size;
+ --StrCountMeter;
+}
+
/* Find the best fit MEM_X_BUF type */
static mem_type
memFindBufSizeType(size_t net_size, size_t * gross_size)
void *memAllocString(size_t net_size, size_t * gross_size) {return memAllocBuf(net_size, gross_size);}
+void *memAllocRigid(size_t net_size)
+{
+ return xmalloc(net_size);
+}
+
void *
memAllocBuf(size_t net_size, size_t * gross_size)
{
void memFree(void *p, int) {xfree(p);}
void memFreeString(size_t, void *buf) {xfree(buf);}
+void memFreeRigid(void *buf, size_t) {xfree(buf);}
void memFreeBuf(size_t, void *buf) {xfree(buf);}
static void cxx_xfree(void * ptr) {xfree(ptr);}
FREE *memFreeBufFunc(size_t) {return cxx_xfree;}