Refactor Pickle Read methods to use higher performance PickleIterator.
There was a lot of redundant error checking and initialization code in all Pickle Read methods because of the void** iterator type. This change replaces the void* iterator with PickleIterator, which encapsulates the read pointer so that less error checking and initialization code is needed for reading.
PickleIterator has all the necessary data to do the actual reading. The advantage of having it provide Read methods (as opposed to leaving them solely in the Pickle interface) is that the callers do not need to pass around the const Pickle* once they have a PickleIterator.
Followup CLs will refactor the call sites to remove const Pickle* arguments where they are now unnecessary. Then the Pickle::Read* methods can be removed entirely.
The alternative approach would have been to change the Pickle::Read methods to non-const and remove the iterator parameter (making Read methods advance an internal read pointer). Unfortunately, the const Read with iterator design is entrenched throughout the chromium code, making this a much more complex change with the same performance outcome.
BUG=13108
Review URL: https://chromiumcodereview.appspot.com/9447084
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125447 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ppapi/proxy/ppapi_param_traits.cc b/ppapi/proxy/ppapi_param_traits.cc
index 484cb9b..7c13710 100644
--- a/ppapi/proxy/ppapi_param_traits.cc
+++ b/ppapi/proxy/ppapi_param_traits.cc
@@ -39,7 +39,7 @@
// add it to the vector one at a time.
template<typename T>
bool ReadVectorWithoutCopy(const Message* m,
- void** iter,
+ PickleIterator* iter,
std::vector<T>* output) {
// This part is just a copy of the the default ParamTraits vector Read().
int size;
@@ -81,7 +81,9 @@
}
// static
-bool ParamTraits<PP_Bool>::Read(const Message* m, void** iter, param_type* r) {
+bool ParamTraits<PP_Bool>::Read(const Message* m,
+ PickleIterator* iter,
+ param_type* r) {
// We specifically want to be strict here about what types of input we accept,
// which ParamTraits<bool> does for us. We don't want to deserialize "2" into
// a PP_Bool, for example.
@@ -109,7 +111,7 @@
}
// static
-bool ParamTraits<PP_FileInfo>::Read(const Message* m, void** iter,
+bool ParamTraits<PP_FileInfo>::Read(const Message* m, PickleIterator* iter,
param_type* r) {
int type, system_type;
if (!ParamTraits<int64_t>::Read(m, iter, &r->size) ||
@@ -148,7 +150,7 @@
// static
bool ParamTraits<PP_NetAddress_Private>::Read(const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* p) {
uint16 size;
if (!ReadParam(m, iter, &size))
@@ -181,7 +183,7 @@
// static
bool ParamTraits<PP_ObjectProperty>::Read(const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* r) {
// FIXME(brettw);
return true;
@@ -220,7 +222,7 @@
// static
bool ParamTraits<ppapi::proxy::PPBFlash_DrawGlyphs_Params>::Read(
const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* r) {
return
ParamTraits<PP_Instance>::Read(m, iter, &r->instance) &&
@@ -265,7 +267,7 @@
// static
bool ParamTraits<ppapi::PPB_FileRef_CreateInfo>::Read(const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* r) {
return
ParamTraits<ppapi::HostResource>::Read(m, iter, &r->resource) &&
@@ -296,7 +298,7 @@
// static
bool ParamTraits<ppapi::proxy::PPBURLLoader_UpdateProgress_Params>::Read(
const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* r) {
return
ParamTraits<PP_Instance>::Read(m, iter, &r->instance) &&
@@ -324,7 +326,7 @@
// static
bool ParamTraits<ppapi::proxy::SerializedDirEntry>::Read(const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* r) {
return ParamTraits<std::string>::Read(m, iter, &r->name) &&
ParamTraits<bool>::Read(m, iter, &r->is_dir);
@@ -354,7 +356,7 @@
// static
bool ParamTraits<ppapi::proxy::SerializedFontDescription>::Read(
const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* r) {
return
ParamTraits<ppapi::proxy::SerializedVar>::Read(m, iter, &r->face) &&
@@ -384,7 +386,7 @@
// static
bool ParamTraits<ppapi::HostResource>::Read(const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* r) {
PP_Instance instance;
PP_Resource resource;
@@ -410,7 +412,7 @@
// static
bool ParamTraits<ppapi::proxy::SerializedVar>::Read(const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* r) {
return r->ReadFromMessage(m, iter);
}
@@ -431,7 +433,7 @@
// static
bool ParamTraits< std::vector<ppapi::proxy::SerializedVar> >::Read(
const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* r) {
return ReadVectorWithoutCopy(m, iter, r);
}
@@ -453,7 +455,7 @@
// static
bool ParamTraits< std::vector<ppapi::PPB_FileRef_CreateInfo> >::Read(
const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* r) {
return ReadVectorWithoutCopy(m, iter, r);
}
@@ -475,7 +477,7 @@
// static
bool ParamTraits<ppapi::proxy::SerializedFlashMenu>::Read(const Message* m,
- void** iter,
+ PickleIterator* iter,
param_type* r) {
return r->ReadFromMessage(m, iter);
}