From cce6eaa238a2bb4d64ccb4450d6f39320fe5434c Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Tue, 13 Nov 2007 21:33:16 +0000 Subject: Stopped frameset from assembling messages piecewise. Roughly halves allocations on the broker, not much effect on client. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@594647 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/framing/FrameSet.cpp | 16 +++++++++------- cpp/src/qpid/framing/TypeFilter.h | 33 ++++++++++++++++----------------- cpp/src/qpid/framing/frame_functors.h | 8 -------- 3 files changed, 25 insertions(+), 32 deletions(-) (limited to 'cpp/src/qpid/framing') diff --git a/cpp/src/qpid/framing/FrameSet.cpp b/cpp/src/qpid/framing/FrameSet.cpp index b361076ee7..9d9b7bc8f8 100644 --- a/cpp/src/qpid/framing/FrameSet.cpp +++ b/cpp/src/qpid/framing/FrameSet.cpp @@ -64,18 +64,20 @@ AMQHeaderBody* FrameSet::getHeaders() uint64_t FrameSet::getContentSize() const { SumBodySize sum; - map_if(sum, TypeFilter(CONTENT_BODY)); + map_if(sum, TypeFilter()); return sum.getSize(); } -void FrameSet::getContent(std::string& out) const -{ - AccumulateContent accumulator(out); - map_if(accumulator, TypeFilter(CONTENT_BODY)); +void FrameSet::getContent(std::string& out) const { + out.clear(); + out.reserve(getContentSize()); + for(Frames::const_iterator i = parts.begin(); i != parts.end(); i++) { + if (i->getBody()->type() == CONTENT_BODY) + out += i->castBody()->getData(); + } } -std::string FrameSet::getContent() const -{ +std::string FrameSet::getContent() const { std::string out; getContent(out); return out; diff --git a/cpp/src/qpid/framing/TypeFilter.h b/cpp/src/qpid/framing/TypeFilter.h index 3a607190fd..d1c42de583 100644 --- a/cpp/src/qpid/framing/TypeFilter.h +++ b/cpp/src/qpid/framing/TypeFilter.h @@ -1,3 +1,6 @@ +#ifndef QPID_FRAMING_TYPEFILTER_H +#define QPID_FRAMING_TYPEFILTER_H + /* * * Licensed to the Apache Software Foundation (ASF) under one @@ -23,30 +26,26 @@ #include "qpid/framing/AMQFrame.h" #include "qpid/framing/FrameHandler.h" -#ifndef _TypeFilter_ -#define _TypeFilter_ - namespace qpid { namespace framing { /** * Predicate that selects frames by type */ -class TypeFilter -{ - std::vector types; -public: - TypeFilter(uint8_t type) { add(type); } - TypeFilter(uint8_t type1, uint8_t type2) { add(type1); add(type2); } - void add(uint8_t type) { types.push_back(type); } - bool operator()(const AMQFrame& f) const - { - return find(types.begin(), types.end(), f.getBody()->type()) != types.end(); - } +template +struct TypeFilter { + bool operator()(const AMQFrame& f) const { + return f.getBody()->type() == Type; + } }; -} -} +template +struct TypeFilter2 { + bool operator()(const AMQFrame& f) const { + return f.getBody()->type() == T1 || f.getBody()->type() == T2; + } +}; +}} // namespace qpid::framing -#endif +#endif /*!QPID_FRAMING_TYPEFILTER_H*/ diff --git a/cpp/src/qpid/framing/frame_functors.h b/cpp/src/qpid/framing/frame_functors.h index 992d389faf..d915a270c2 100644 --- a/cpp/src/qpid/framing/frame_functors.h +++ b/cpp/src/qpid/framing/frame_functors.h @@ -74,14 +74,6 @@ public: void operator()(const AMQFrame& f) { f.getBody()->encode(buffer); } }; -class AccumulateContent -{ - std::string& content; -public: - AccumulateContent(std::string& c) : content(c) {} - void operator()(const AMQFrame& f) { content += f.castBody()->getData(); } -}; - /** * Sends a copy of the frame its applied to to the specified handler */ -- cgit v1.2.1