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

Unified Diff: ppapi/proxy/plugin_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/plugin_var_serialization_rules.h ('k') | ppapi/proxy/ppp_messaging_proxy_perftest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/proxy/plugin_var_serialization_rules.cc
diff --git a/ppapi/proxy/plugin_var_serialization_rules.cc b/ppapi/proxy/plugin_var_serialization_rules.cc
index 2e92dd57ba8f1f3af534e0e7f38f47d9ba21b329..87a3cc2a8ff89cc4cbd77dc3f9d1ebda1c8997e5 100644
--- a/ppapi/proxy/plugin_var_serialization_rules.cc
+++ b/ppapi/proxy/plugin_var_serialization_rules.cc
@@ -22,17 +22,19 @@ PluginVarSerializationRules::PluginVarSerializationRules()
PluginVarSerializationRules::~PluginVarSerializationRules() {
}
-PP_Var PluginVarSerializationRules::SendCallerOwned(const PP_Var& var,
- std::string* str_val) {
+PP_Var PluginVarSerializationRules::SendCallerOwned(
+ const PP_Var& var,
+ const std::string** str_ptr_out) {
// Objects need special translations to get the IDs valid in the host.
if (var.type == PP_VARTYPE_OBJECT)
return var_tracker_->GetHostObject(var);
- // Retrieve the string to use for IPC.
+ // Retrieve the pointer to the string in the tracker in order to send the
+ // string over IPC without unnecessary copies.
if (var.type == PP_VARTYPE_STRING) {
StringVar* string_var = StringVar::FromPPVar(var);
if (string_var)
- *str_val = string_var->value();
+ *str_ptr_out = string_var->ptr();
else
NOTREACHED() << "Trying to send unknown string over IPC.";
}
@@ -41,10 +43,10 @@ PP_Var PluginVarSerializationRules::SendCallerOwned(const PP_Var& var,
PP_Var PluginVarSerializationRules::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);
+ return StringVar::StringToPPVar(str.Pass());
if (var.type == PP_VARTYPE_OBJECT) {
DCHECK(dispatcher->IsPlugin());
@@ -65,10 +67,10 @@ void PluginVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) {
}
PP_Var PluginVarSerializationRules::ReceivePassRef(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);
+ return StringVar::StringToPPVar(str.Pass());
// Overview of sending an object with "pass ref" from the browser to the
// plugin:
@@ -96,8 +98,9 @@ PP_Var PluginVarSerializationRules::ReceivePassRef(const PP_Var& var,
return var;
}
-PP_Var PluginVarSerializationRules::BeginSendPassRef(const PP_Var& var,
- std::string* str_val) {
+PP_Var PluginVarSerializationRules::BeginSendPassRef(
+ const PP_Var& var,
+ const std::string** str_ptr_out) {
// Overview of sending an object with "pass ref" from the plugin to the
// browser:
// Example 1 Example 2
@@ -118,9 +121,11 @@ PP_Var PluginVarSerializationRules::BeginSendPassRef(const PP_Var& var,
return var_tracker_->GetHostObject(var);
if (var.type == PP_VARTYPE_STRING) {
+ // Get the pointer to the string that's in the tracker and return it, so we
+ // can avoid an extra copy of the string when serializing over IPC.
StringVar* string_var = StringVar::FromPPVar(var);
if (string_var)
- *str_val = string_var->value();
+ *str_ptr_out = string_var->ptr();
else
NOTREACHED() << "Trying to send unknown string over IPC.";
}
« no previous file with comments | « ppapi/proxy/plugin_var_serialization_rules.h ('k') | ppapi/proxy/ppp_messaging_proxy_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698