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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 39363002: Optimize ParamTraits<float> and ParamTraits<double> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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 | « ipc/ipc_message_utils.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ipc/ipc_message_utils.h" 5 #include "ipc/ipc_message_utils.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/nullable_string16.h" 10 #include "base/strings/nullable_string16.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 304 }
305 305
306 void ParamTraits<long long>::Log(const param_type& p, std::string* l) { 306 void ParamTraits<long long>::Log(const param_type& p, std::string* l) {
307 l->append(base::Int64ToString(static_cast<int64>(p))); 307 l->append(base::Int64ToString(static_cast<int64>(p)));
308 } 308 }
309 309
310 void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) { 310 void ParamTraits<unsigned long long>::Log(const param_type& p, std::string* l) {
311 l->append(base::Uint64ToString(p)); 311 l->append(base::Uint64ToString(p));
312 } 312 }
313 313
314 void ParamTraits<float>::Write(Message* m, const param_type& p) {
315 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type));
316 }
317
318 bool ParamTraits<float>::Read(const Message* m, PickleIterator* iter,
319 param_type* r) {
320 const char *data;
321 int data_size;
322 if (!m->ReadData(iter, &data, &data_size) ||
323 data_size != sizeof(param_type)) {
324 NOTREACHED();
325 return false;
326 }
327 memcpy(r, data, sizeof(param_type));
328 return true;
329 }
330
331 void ParamTraits<float>::Log(const param_type& p, std::string* l) { 314 void ParamTraits<float>::Log(const param_type& p, std::string* l) {
332 l->append(base::StringPrintf("%e", p)); 315 l->append(base::StringPrintf("%e", p));
333 } 316 }
334 317
335 void ParamTraits<double>::Write(Message* m, const param_type& p) { 318 void ParamTraits<double>::Write(Message* m, const param_type& p) {
336 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(param_type)); 319 m->WriteBytes(reinterpret_cast<const char*>(&p), sizeof(param_type));
337 } 320 }
338 321
339 bool ParamTraits<double>::Read(const Message* m, PickleIterator* iter, 322 bool ParamTraits<double>::Read(const Message* m, PickleIterator* iter,
340 param_type* r) { 323 param_type* r) {
341 const char *data; 324 const char *data;
342 int data_size; 325 if (!m->ReadBytes(iter, &data, sizeof(*r))) {
343 if (!m->ReadData(iter, &data, &data_size) ||
344 data_size != sizeof(param_type)) {
345 NOTREACHED(); 326 NOTREACHED();
346 return false; 327 return false;
347 } 328 }
348 memcpy(r, data, sizeof(param_type)); 329 memcpy(r, data, sizeof(param_type));
349 return true; 330 return true;
350 } 331 }
351 332
352 void ParamTraits<double>::Log(const param_type& p, std::string* l) { 333 void ParamTraits<double>::Log(const param_type& p, std::string* l) {
353 l->append(base::StringPrintf("%e", p)); 334 l->append(base::StringPrintf("%e", p));
354 } 335 }
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 return result; 823 return result;
843 } 824 }
844 825
845 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) { 826 void ParamTraits<MSG>::Log(const param_type& p, std::string* l) {
846 l->append("<MSG>"); 827 l->append("<MSG>");
847 } 828 }
848 829
849 #endif // OS_WIN 830 #endif // OS_WIN
850 831
851 } // namespace IPC 832 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_message_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698