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

Unified Diff: ppapi/shared_impl/var.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/shared_impl/var.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/shared_impl/var.cc
diff --git a/ppapi/shared_impl/var.cc b/ppapi/shared_impl/var.cc
index 60d439bd6b3f0099830a6a33b5e5c3c40030ac2d..3fce7e3180fadf8102f56ddf4388c3455cfa845c 100644
--- a/ppapi/shared_impl/var.cc
+++ b/ppapi/shared_impl/var.cc
@@ -124,6 +124,11 @@ StringVar::StringVar(const char* str, uint32 len)
StringVar::~StringVar() {
}
+StringVar::StringVar(scoped_ptr<std::string> str) {
+ // Swap the given string's contents in to value to avoid copying.
+ str->swap(value_);
+}
+
StringVar* StringVar::AsStringVar() {
return this;
}
@@ -146,6 +151,17 @@ PP_Var StringVar::StringToPPVar(const char* data, uint32 len) {
}
// static
+PP_Var StringVar::StringToPPVar(scoped_ptr<std::string> str) {
+ DCHECK(str.get());
+ if (!str.get())
+ return PP_MakeNull();
+ scoped_refptr<StringVar> str_var(new StringVar(str.Pass()));
+ if (!str_var || !IsStringUTF8(str_var->value()))
+ return PP_MakeNull();
+ return str_var->GetPPVar();
+}
+
+// static
StringVar* StringVar::FromPPVar(PP_Var var) {
if (var.type != PP_VARTYPE_STRING)
return NULL;
« no previous file with comments | « ppapi/shared_impl/var.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698