Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: ppapi/proxy/host_var_serialization_rules.cc

Issue 9138027: PPAPI: Reduce string copying in SerializedVar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Duh Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/proxy/host_var_serialization_rules.h ('k') | ppapi/proxy/plugin_var_serialization_rules.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/host_var_serialization_rules.cc
diff --git a/ppapi/proxy/host_var_serialization_rules.cc b/ppapi/proxy/host_var_serialization_rules.cc
index 3f11090feb112e53343c35ea9a5708f2cfbee195..45eaf4026382a2bc39d95643da32c80e27018214 100644
--- a/ppapi/proxy/host_var_serialization_rules.cc
+++ b/ppapi/proxy/host_var_serialization_rules.cc
@@ -24,19 +24,24 @@ HostVarSerializationRules::HostVarSerializationRules(PP_Module pp_module)
HostVarSerializationRules::~HostVarSerializationRules() {
}
-PP_Var HostVarSerializationRules::SendCallerOwned(const PP_Var& var,
- std::string* str_val) {
+PP_Var HostVarSerializationRules::SendCallerOwned(
+ const PP_Var& var,
+ const std::string** str_ptr_out) {
if (var.type == PP_VARTYPE_STRING)
- VarToString(var, str_val);
+ VarToStringPtr(var, str_ptr_out);
return var;
}
PP_Var HostVarSerializationRules::BeginReceiveCallerOwned(
const PP_Var& var,
- const std::string* str_val,
+ scoped_ptr<std::string> str,
Dispatcher* /* dispatcher */) {
- if (var.type == PP_VARTYPE_STRING)
- return StringVar::StringToPPVar(*str_val);
+ if (var.type == PP_VARTYPE_STRING) {
+ // Put the string in to the VarTracker (transferring ownership, since we
+ // would otherwise just delete the one we received from IPC). This allows
+ // us to avoid unnecessary copying of the string.
+ return StringVar::StringToPPVar(str.Pass());
+ }
return var;
}
@@ -47,12 +52,13 @@ void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) {
}
}
-PP_Var HostVarSerializationRules::ReceivePassRef(const PP_Var& var,
- const std::string& str_val,
- Dispatcher* /* dispatcher */) {
+PP_Var HostVarSerializationRules::ReceivePassRef(
+ const PP_Var& var,
+ scoped_ptr<std::string> str,
+ Dispatcher* /* dispatcher */) {
if (var.type == PP_VARTYPE_STRING) {
- // Convert the string to the context of the current process.
- return StringVar::StringToPPVar(str_val);
+ // Put the string in to the tracker, transferring ownership.
+ return StringVar::StringToPPVar(str.Pass());
}
// See PluginVarSerialization::BeginSendPassRef for an example.
@@ -61,12 +67,13 @@ PP_Var HostVarSerializationRules::ReceivePassRef(const PP_Var& var,
return var;
}
-PP_Var HostVarSerializationRules::BeginSendPassRef(const PP_Var& var,
- std::string* str_val) {
+PP_Var HostVarSerializationRules::BeginSendPassRef(
+ const PP_Var& var,
+ const std::string** str_ptr_out) {
// See PluginVarSerialization::ReceivePassRef for an example. We don't need
// to do anything here other than convert the string.
if (var.type == PP_VARTYPE_STRING)
- VarToString(var, str_val);
+ VarToStringPtr(var, str_ptr_out);
return var;
}
@@ -76,16 +83,14 @@ void HostVarSerializationRules::EndSendPassRef(const PP_Var& /* var */,
// to do anything here.
}
-void HostVarSerializationRules::VarToString(const PP_Var& var,
- std::string* str) {
+void HostVarSerializationRules::VarToStringPtr(
+ const PP_Var& var,
+ const std::string** str_ptr_out) {
DCHECK(var.type == PP_VARTYPE_STRING);
-
- // This could be optimized to avoid an extra string copy by going to a lower
- // level of the browser's implementation of strings where we already have
- // a std::string.
+ *str_ptr_out = NULL;
StringVar* string_var = StringVar::FromPPVar(var);
if (string_var)
- *str = string_var->value();
+ *str_ptr_out = string_var->ptr();
}
void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) {
« no previous file with comments | « ppapi/proxy/host_var_serialization_rules.h ('k') | ppapi/proxy/plugin_var_serialization_rules.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698