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

Side by Side 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, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/var.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/shared_impl/var.h" 5 #include "ppapi/shared_impl/var.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 : value_(str) { 117 : value_(str) {
118 } 118 }
119 119
120 StringVar::StringVar(const char* str, uint32 len) 120 StringVar::StringVar(const char* str, uint32 len)
121 : value_(str, len) { 121 : value_(str, len) {
122 } 122 }
123 123
124 StringVar::~StringVar() { 124 StringVar::~StringVar() {
125 } 125 }
126 126
127 StringVar::StringVar(scoped_ptr<std::string> str) {
128 // Swap the given string's contents in to value to avoid copying.
129 str->swap(value_);
130 }
131
127 StringVar* StringVar::AsStringVar() { 132 StringVar* StringVar::AsStringVar() {
128 return this; 133 return this;
129 } 134 }
130 135
131 PP_VarType StringVar::GetType() const { 136 PP_VarType StringVar::GetType() const {
132 return PP_VARTYPE_STRING; 137 return PP_VARTYPE_STRING;
133 } 138 }
134 139
135 // static 140 // static
136 PP_Var StringVar::StringToPPVar(const std::string& var) { 141 PP_Var StringVar::StringToPPVar(const std::string& var) {
137 return StringToPPVar(var.c_str(), var.size()); 142 return StringToPPVar(var.c_str(), var.size());
138 } 143 }
139 144
140 // static 145 // static
141 PP_Var StringVar::StringToPPVar(const char* data, uint32 len) { 146 PP_Var StringVar::StringToPPVar(const char* data, uint32 len) {
142 scoped_refptr<StringVar> str(new StringVar(data, len)); 147 scoped_refptr<StringVar> str(new StringVar(data, len));
143 if (!str || !IsStringUTF8(str->value())) 148 if (!str || !IsStringUTF8(str->value()))
144 return PP_MakeNull(); 149 return PP_MakeNull();
145 return str->GetPPVar(); 150 return str->GetPPVar();
146 } 151 }
147 152
148 // static 153 // static
154 PP_Var StringVar::StringToPPVar(scoped_ptr<std::string> str) {
155 DCHECK(str.get());
156 if (!str.get())
157 return PP_MakeNull();
158 scoped_refptr<StringVar> str_var(new StringVar(str.Pass()));
159 if (!str_var || !IsStringUTF8(str_var->value()))
160 return PP_MakeNull();
161 return str_var->GetPPVar();
162 }
163
164 // static
149 StringVar* StringVar::FromPPVar(PP_Var var) { 165 StringVar* StringVar::FromPPVar(PP_Var var) {
150 if (var.type != PP_VARTYPE_STRING) 166 if (var.type != PP_VARTYPE_STRING)
151 return NULL; 167 return NULL;
152 scoped_refptr<Var> var_object( 168 scoped_refptr<Var> var_object(
153 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); 169 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
154 if (!var_object) 170 if (!var_object)
155 return NULL; 171 return NULL;
156 return var_object->AsStringVar(); 172 return var_object->AsStringVar();
157 } 173 }
158 174
(...skipping 19 matching lines...) Expand all
178 return NULL; 194 return NULL;
179 scoped_refptr<Var> var_object( 195 scoped_refptr<Var> var_object(
180 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); 196 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
181 if (!var_object) 197 if (!var_object)
182 return NULL; 198 return NULL;
183 return var_object->AsArrayBufferVar(); 199 return var_object->AsArrayBufferVar();
184 } 200 }
185 201
186 } // namespace ppapi 202 } // namespace ppapi
187 203
OLDNEW
« 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