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

Unified Diff: mojo/system/memory.h

Issue 419973005: Convert WriteMessage...() to use the new user pointer handling (see r285350). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | « mojo/system/dispatcher_unittest.cc ('k') | mojo/system/message_in_transit.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/system/memory.h
diff --git a/mojo/system/memory.h b/mojo/system/memory.h
index 0d235737bd4c456853d2625392948c01b7bccd55..65ccd291c0e72951a333f16d9ee2efc93516e9d8 100644
--- a/mojo/system/memory.h
+++ b/mojo/system/memory.h
@@ -129,7 +129,17 @@ class UserPointer {
return *pointer_;
}
- // TODO(vtl): Add a |GetArray()| method (see |PutArray()|).
+ // Gets an array (of type |Type|, or just a buffer if |Type| is |void| or
+ // |const void|) of |count| elements (or bytes if |Type| is |void| or |const
+ // void|) from the location pointed to by this user pointer. Use this when
+ // you'd do something like |memcpy(destination, user_pointer, count *
+ // sizeof(Type)|.
+ void GetArray(typename internal::remove_const<Type>::type* destination,
+ size_t count) {
+ internal::CheckUserPointerWithCountHelper<
+ sizeof(NonVoidType), MOJO_ALIGNOF(NonVoidType)>(pointer_, count);
+ memcpy(destination, pointer_, count * sizeof(NonVoidType));
+ }
// Puts a value (of type |Type|, or of type |char| if |Type| is |void|) to the
// location pointed to by this user pointer. Use this when you'd use the
@@ -158,17 +168,16 @@ class UserPointer {
*pointer_ = value;
}
- // Puts an array (of type |Type|, or just a buffer if |Type| is |void|) and
- // size |count| (number of elements, or number of bytes if |Type| is |void|)
- // to the location pointed to by this user pointer. Use this when you'd do
- // something like |memcpy(user_pointer, source, count * sizeof(Type))|.
+ // Puts an array (of type |Type|, or just a buffer if |Type| is |void|) with
+ // |count| elements (or bytes |Type| is |void|) to the location pointed to by
+ // this user pointer. Use this when you'd do something like
+ // |memcpy(user_pointer, source, count * sizeof(Type))|.
//
// Note: The same comments about the validity of |Put()| (except for the part
// about |void|) apply here.
void PutArray(const Type* source, size_t count) {
- internal::CheckUserPointerWithCountHelper<sizeof(NonVoidType),
- MOJO_ALIGNOF(NonVoidType)>(source,
- count);
+ internal::CheckUserPointerWithCountHelper<
+ sizeof(NonVoidType), MOJO_ALIGNOF(NonVoidType)>(pointer_, count);
memcpy(pointer_, source, count * sizeof(NonVoidType));
}
« no previous file with comments | « mojo/system/dispatcher_unittest.cc ('k') | mojo/system/message_in_transit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698