summaryrefslogtreecommitdiffstats
path: root/ipc/ipc_message_utils.h
diff options
context:
space:
mode:
authorjdduke@chromium.org <jdduke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-18 20:48:35 +0000
committerjdduke@chromium.org <jdduke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-18 20:48:35 +0000
commit205294bddfb47d6581a9dd961e95cd01ead71cac (patch)
treeaad74f4095411b4f81b0febf1705a796ac1434da /ipc/ipc_message_utils.h
parent6c0507960c2634185ed3df13f75e31ecdaceda34 (diff)
downloadchromium_src-205294bddfb47d6581a9dd961e95cd01ead71cac.zip
chromium_src-205294bddfb47d6581a9dd961e95cd01ead71cac.tar.gz
chromium_src-205294bddfb47d6581a9dd961e95cd01ead71cac.tar.bz2
Replace std::map with base::SmallMap in ui::LatencyInfo
The typical number of components per LatencyInfo instance is quite small. Avoid unnecessary heap allocation by using a SmallMap to store component entries. This reduces the average browser send time cost per touch or scroll event by ~15us on a Nexus 4, and ~22us on a Galaxy Nexus. BUG=341613 Review URL: https://codereview.chromium.org/157003005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257740 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc/ipc_message_utils.h')
-rw-r--r--ipc/ipc_message_utils.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h
index b05f76d..102992d 100644
--- a/ipc/ipc_message_utils.h
+++ b/ipc/ipc_message_utils.h
@@ -11,6 +11,7 @@
#include <string>
#include <vector>
+#include "base/containers/small_map.h"
#include "base/files/file.h"
#include "base/format_macros.h"
#include "base/memory/scoped_vector.h"
@@ -670,6 +671,41 @@ struct ParamTraits<ScopedVector<P> > {
}
};
+template <typename NormalMap,
+ int kArraySize,
+ typename EqualKey,
+ typename MapInit>
+struct ParamTraits<base::SmallMap<NormalMap, kArraySize, EqualKey, MapInit> > {
+ typedef base::SmallMap<NormalMap, kArraySize, EqualKey, MapInit> param_type;
+ typedef typename param_type::key_type K;
+ typedef typename param_type::data_type V;
+ static void Write(Message* m, const param_type& p) {
+ WriteParam(m, static_cast<int>(p.size()));
+ typename param_type::const_iterator iter;
+ for (iter = p.begin(); iter != p.end(); ++iter) {
+ WriteParam(m, iter->first);
+ WriteParam(m, iter->second);
+ }
+ }
+ static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
+ int size;
+ if (!m->ReadLength(iter, &size))
+ return false;
+ for (int i = 0; i < size; ++i) {
+ K key;
+ if (!ReadParam(m, iter, &key))
+ return false;
+ V& value = (*r)[key];
+ if (!ReadParam(m, iter, &value))
+ return false;
+ }
+ return true;
+ }
+ static void Log(const param_type& p, std::string* l) {
+ l->append("<base::SmallMap>");
+ }
+};
+
// IPC types ParamTraits -------------------------------------------------------
// A ChannelHandle is basically a platform-inspecific wrapper around the