diff options
author | Andrew Stitcher <astitcher@apache.org> | 2012-03-05 19:12:43 +0000 |
---|---|---|
committer | Andrew Stitcher <astitcher@apache.org> | 2012-03-05 19:12:43 +0000 |
commit | 822e4b0752fbff6284129f8bd85e529fc92bb3fa (patch) | |
tree | 057775b6cfa6b6607b768f264164e84ec3b1dda2 | |
parent | 91361618c09bc49e7fdf0a0909ee3d6df8e7d495 (diff) | |
download | qpid-python-822e4b0752fbff6284129f8bd85e529fc92bb3fa.tar.gz |
QPID-3883: Using application headers in messages causes a very large slowdown
Cache the size of a field table to prevent recomputation
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1297184 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/include/qpid/framing/FieldTable.h | 5 | ||||
-rw-r--r-- | qpid/cpp/src/qpid/framing/FieldTable.cpp | 33 |
2 files changed, 34 insertions, 4 deletions
diff --git a/qpid/cpp/include/qpid/framing/FieldTable.h b/qpid/cpp/include/qpid/framing/FieldTable.h index bdcef6d7fd..ce0374d829 100644 --- a/qpid/cpp/include/qpid/framing/FieldTable.h +++ b/qpid/cpp/include/qpid/framing/FieldTable.h @@ -56,7 +56,7 @@ class FieldTable typedef ValueMap::reference reference; typedef ValueMap::value_type value_type; - QPID_COMMON_INLINE_EXTERN FieldTable() {}; + QPID_COMMON_EXTERN FieldTable(); QPID_COMMON_EXTERN FieldTable(const FieldTable& ft); QPID_COMMON_EXTERN ~FieldTable(); QPID_COMMON_EXTERN FieldTable& operator=(const FieldTable& ft); @@ -109,7 +109,7 @@ class FieldTable QPID_COMMON_EXTERN std::pair <ValueMap::iterator, bool> insert(const ValueMap::value_type&); QPID_COMMON_EXTERN ValueMap::iterator insert(ValueMap::iterator, const ValueMap::value_type&); - void clear() { values.clear(); } + void clear(); // ### Hack Alert @@ -117,6 +117,7 @@ class FieldTable private: ValueMap values; + mutable uint32_t cachedSize; // if = 0 then non cached size as 0 is not a legal size QPID_COMMON_EXTERN friend std::ostream& operator<<(std::ostream& out, const FieldTable& body); }; diff --git a/qpid/cpp/src/qpid/framing/FieldTable.cpp b/qpid/cpp/src/qpid/framing/FieldTable.cpp index f80d2f9fb1..d5c42c3ade 100644 --- a/qpid/cpp/src/qpid/framing/FieldTable.cpp +++ b/qpid/cpp/src/qpid/framing/FieldTable.cpp @@ -31,6 +31,10 @@ namespace qpid { namespace framing { +FieldTable::FieldTable() : cachedSize(0) +{ +} + FieldTable::FieldTable(const FieldTable& ft) { *this = ft; @@ -40,17 +44,22 @@ FieldTable& FieldTable::operator=(const FieldTable& ft) { clear(); values = ft.values; + cachedSize = ft.cachedSize; return *this; } FieldTable::~FieldTable() {} uint32_t FieldTable::encodedSize() const { + if (cachedSize != 0) { + return cachedSize; + } uint32_t len(4/*size field*/ + 4/*count field*/); for(ValueMap::const_iterator i = values.begin(); i != values.end(); ++i) { // shortstr_len_byte + key size + value size - len += 1 + (i->first).size() + (i->second)->encodedSize(); + len += 1 + (i->first).size() + (i->second)->encodedSize(); } + cachedSize = len; return len; } @@ -78,43 +87,53 @@ std::ostream& operator<<(std::ostream& out, const FieldTable& t) { void FieldTable::set(const std::string& name, const ValuePtr& value){ values[name] = value; + cachedSize = 0; } void FieldTable::setString(const std::string& name, const std::string& value){ values[name] = ValuePtr(new Str16Value(value)); + cachedSize = 0; } void FieldTable::setInt(const std::string& name, const int value){ values[name] = ValuePtr(new IntegerValue(value)); + cachedSize = 0; } void FieldTable::setInt64(const std::string& name, const int64_t value){ values[name] = ValuePtr(new Integer64Value(value)); + cachedSize = 0; } void FieldTable::setTimestamp(const std::string& name, const uint64_t value){ values[name] = ValuePtr(new TimeValue(value)); + cachedSize = 0; } void FieldTable::setUInt64(const std::string& name, const uint64_t value){ values[name] = ValuePtr(new Unsigned64Value(value)); + cachedSize = 0; } void FieldTable::setTable(const std::string& name, const FieldTable& value) { values[name] = ValuePtr(new FieldTableValue(value)); + cachedSize = 0; } void FieldTable::setArray(const std::string& name, const Array& value) { values[name] = ValuePtr(new ArrayValue(value)); + cachedSize = 0; } void FieldTable::setFloat(const std::string& name, const float value){ values[name] = ValuePtr(new FloatValue(value)); + cachedSize = 0; } void FieldTable::setDouble(const std::string& name, double value){ values[name] = ValuePtr(new DoubleValue(value)); + cachedSize = 0; } FieldTable::ValuePtr FieldTable::get(const std::string& name) const @@ -216,6 +235,7 @@ void FieldTable::decode(Buffer& buffer){ values[name] = ValuePtr(value); } } + cachedSize = 0; } bool FieldTable::operator==(const FieldTable& x) const { @@ -230,17 +250,26 @@ bool FieldTable::operator==(const FieldTable& x) const { void FieldTable::erase(const std::string& name) { - if (values.find(name) != values.end()) + if (values.find(name) != values.end()) { values.erase(name); + cachedSize = 0; + } +} +void FieldTable::clear() +{ + values.clear(); + cachedSize = 0; } std::pair<FieldTable::ValueMap::iterator, bool> FieldTable::insert(const ValueMap::value_type& value) { + cachedSize = 0; return values.insert(value); } FieldTable::ValueMap::iterator FieldTable::insert(ValueMap::iterator position, const ValueMap::value_type& value) { + cachedSize = 0; return values.insert(position, value); } |