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

Unified Diff: components/rappor/byte_vector_utils.cc

Issue 1112003002: Use 64 bit shift when convert uint64_t to ByteVector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
Index: components/rappor/byte_vector_utils.cc
diff --git a/components/rappor/byte_vector_utils.cc b/components/rappor/byte_vector_utils.cc
index 69abcd4dffd8e3c8cfb55061c8aa2cc58c61cedf..02120cc2fd4b30659bf127d3f55bf73d840d3c83 100644
--- a/components/rappor/byte_vector_utils.cc
+++ b/components/rappor/byte_vector_utils.cc
@@ -78,6 +78,17 @@ bool HMAC_DRBG_Update(const std::string& provided_data,
} // namespace
+void Uint64ToByteVector(uint64_t value, uint64_t size, ByteVector* output) {
+ DCHECK_LE(size, 8u);
+ DCHECK_EQ(size, output->size());
+ for (size_t i = 0; i < size; i++) {
+ // Get the value of the i-th smallest byte and copy it to the byte vector.
+ uint64_t shift = i * 8;
brucedawson 2015/04/29 18:21:51 Why is shift a uint64_t? The legal values are from
+ uint64_t byte_mask = uint64_t(0xff) << shift;
Alexei Svitkine (slow) 2015/04/29 15:01:07 Our style guide prefers static_cast<uint64_t>().
Steven Holte 2015/04/29 18:18:56 Done.
+ (*output)[i] = (value & byte_mask) >> shift;
+ }
+}
+
ByteVector* ByteVectorAnd(const ByteVector& lhs, ByteVector* rhs) {
DCHECK_EQ(lhs.size(), rhs->size());
for (size_t i = 0; i < lhs.size(); ++i) {

Powered by Google App Engine
This is Rietveld 408576698