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

Side by Side Diff: components/variations/metrics_util.cc

Issue 794683005: replace COMPILE_ASSERT with static_assert in components/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: formatting fixup Created 6 years 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
« no previous file with comments | « components/variations/entropy_provider.cc ('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 "components/variations/metrics_util.h" 5 #include "components/variations/metrics_util.h"
6 6
7 #include "base/sha1.h" 7 #include "base/sha1.h"
8 #include "base/sys_byteorder.h" 8 #include "base/sys_byteorder.h"
9 9
10 namespace metrics { 10 namespace metrics {
11 11
12 uint32 HashName(const std::string& name) { 12 uint32 HashName(const std::string& name) {
13 // SHA-1 is designed to produce a uniformly random spread in its output space, 13 // SHA-1 is designed to produce a uniformly random spread in its output space,
14 // even for nearly-identical inputs. 14 // even for nearly-identical inputs.
15 unsigned char sha1_hash[base::kSHA1Length]; 15 unsigned char sha1_hash[base::kSHA1Length];
16 base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(name.c_str()), 16 base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(name.c_str()),
17 name.size(), 17 name.size(),
18 sha1_hash); 18 sha1_hash);
19 19
20 uint32 bits; 20 uint32 bits;
21 COMPILE_ASSERT(sizeof(bits) < sizeof(sha1_hash), need_more_data); 21 static_assert(sizeof(bits) < sizeof(sha1_hash), "more data required");
22 memcpy(&bits, sha1_hash, sizeof(bits)); 22 memcpy(&bits, sha1_hash, sizeof(bits));
23 23
24 return base::ByteSwapToLE32(bits); 24 return base::ByteSwapToLE32(bits);
25 } 25 }
26 26
27 } // namespace metrics 27 } // namespace metrics
OLDNEW
« no previous file with comments | « components/variations/entropy_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698