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

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: Simplify NaCl. 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
« base/rand_util_unittest.cc ('K') | « 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..35f2d2e863ab83f84e0c00dffe19872f808fa43a 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;
bradn 2014/01/22 21:56:12 Any reason not to use: CryptGenRandom ? http://msd
wtc 2014/01/22 22:29:09 There is a better Windows function: RtlGenRandom.
+ 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();
+ size_t copy_count = std::min(output_length - i, random_int_size);
wtc 2014/01/22 22:29:09 |copy_count| can also be 'const'. (I don't do this
DaleCurtis 2014/01/22 22:54:14 Done.
+ memcpy(((uint8*)output) + i, &random_int, copy_count);
+ }
+}
+
} // namespace base
« base/rand_util_unittest.cc ('K') | « base/rand_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698