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

Unified Diff: base/rand_util_win.cc

Issue 140773006: Improve base::RandBytes() performance by 1.75x-2.10x on POSIX. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 6 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 | « base/rand_util_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/rand_util_win.cc
diff --git a/base/rand_util_win.cc b/base/rand_util_win.cc
index 391fe5b9e61d6f48f413b97f3f3f536dd38d5da0..52103eb93e556ce19269edd04cda5c2d2c84fccc 100644
--- a/base/rand_util_win.cc
+++ b/base/rand_util_win.cc
@@ -28,4 +28,14 @@ uint64 RandUint64() {
return (static_cast<uint64>(first_half) << 32) + second_half;
}
+void RandBytes(void* output, size_t output_length) {
+ uint64 random_int;
+ const size_t random_int_size = sizeof(random_int);
+ for (size_t i = 0; i < output_length; i += random_int_size) {
+ random_int = base::RandUint64();
+ const size_t copy_count = std::min(output_length - i, random_int_size);
+ memcpy(((uint8*)output) + i, &random_int, copy_count);
+ }
+}
+
} // namespace base
« no previous file with comments | « base/rand_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698