0

Use base::bits::IsPowerOfTwo() in a couple more places.

Remove redundant implementations.

Change-Id: If4d22652e2714c1c377cfab60302e69af05ab4d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2967351
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Ryan Sleevi <rsleevi@chromium.org>
Reviewed-by: David Benjamin <davidben@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#893540}
This commit is contained in:
Lei Zhang
2021-06-17 19:30:14 +00:00
committed by Chromium LUCI CQ
parent 97e310612b
commit f7f9904ecc
2 changed files with 4 additions and 11 deletions
net/cert
sandbox/linux/bpf_dsl

@ -8,6 +8,7 @@
#include <vector>
#include "base/bits.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/strings/string_piece.h"
@ -31,10 +32,6 @@ const unsigned char kSHA256EmptyStringHash[ct::kSthRootHashLength] = {
0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b,
0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55};
bool IsPowerOfTwo(uint64_t n) {
return n != 0 && (n & (n - 1)) == 0;
}
const EVP_MD* GetEvpAlg(ct::DigitallySigned::HashAlgorithm alg) {
switch (alg) {
case ct::DigitallySigned::HASH_ALGO_MD5:
@ -178,7 +175,7 @@ bool CTLogVerifier::VerifyConsistencyProof(
// "consistency_path" array.
base::StringPiece first_proof_node = old_tree_hash;
auto iter = proof.nodes.begin();
if (!IsPowerOfTwo(proof.first_tree_size)) {
if (!base::bits::IsPowerOfTwo(proof.first_tree_size)) {
if (iter == proof.nodes.end())
return false;
first_proof_node = *iter;

@ -12,6 +12,7 @@
#include <limits>
#include <ostream>
#include "base/bits.h"
#include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "sandbox/linux/bpf_dsl/bpf_dsl.h"
@ -51,11 +52,6 @@ const int kSyscallsRequiredForUnsafeTraps[] = {
#endif
};
bool HasExactlyOneBit(uint64_t x) {
// Common trick; e.g., see http://stackoverflow.com/a/108329.
return x != 0 && (x & (x - 1)) == 0;
}
ResultExpr DefaultPanic(const char* error) {
return Kill();
}
@ -404,7 +400,7 @@ CodeGen::Node PolicyCompiler::MaskedEqualHalf(int argno,
// For (arg & x) == x where x is a single-bit value, emit:
// LDW [idx]
// JSET mask, passed, failed
if (mask == value && HasExactlyOneBit(mask)) {
if (mask == value && base::bits::IsPowerOfTwo(mask)) {
return gen_.MakeInstruction(
BPF_LD + BPF_W + BPF_ABS,
idx,