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

Side by Side Diff: net/disk_cache/bitmap.cc

Issue 10942004: Cleanup: avoid foo ? true : false, part 2. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/escape.cc ('k') | net/disk_cache/entry_impl.cc » ('j') | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "net/disk_cache/bitmap.h" 5 #include "net/disk_cache/bitmap.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
(...skipping 18 matching lines...) Expand all
29 // Returns the index of the first bit set to |value| from |word|. This code 29 // Returns the index of the first bit set to |value| from |word|. This code
30 // assumes that we'll be able to find that bit. 30 // assumes that we'll be able to find that bit.
31 int FindLSBNonEmpty(uint32 word, bool value) { 31 int FindLSBNonEmpty(uint32 word, bool value) {
32 // If we are looking for 0, negate |word| and look for 1. 32 // If we are looking for 0, negate |word| and look for 1.
33 if (!value) 33 if (!value)
34 word = ~word; 34 word = ~word;
35 35
36 return FindLSBSetNonZero(word); 36 return FindLSBSetNonZero(word);
37 } 37 }
38 38
39 } 39 } // namespace
40 40
41 namespace disk_cache { 41 namespace disk_cache {
42 42
43 Bitmap::Bitmap(int num_bits, bool clear_bits) 43 Bitmap::Bitmap(int num_bits, bool clear_bits)
44 : num_bits_(num_bits), 44 : num_bits_(num_bits),
45 array_size_(RequiredArraySize(num_bits)), 45 array_size_(RequiredArraySize(num_bits)),
46 alloc_(true) { 46 alloc_(true) {
47 map_ = new uint32[array_size_]; 47 map_ = new uint32[array_size_];
48 48
49 // Initialize all of the bits. 49 // Initialize all of the bits.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 map_[j] |= (1 << i); 98 map_[j] |= (1 << i);
99 else 99 else
100 map_[j] &= ~(1 << i); 100 map_[j] &= ~(1 << i);
101 } 101 }
102 102
103 bool Bitmap::Get(int index) const { 103 bool Bitmap::Get(int index) const {
104 DCHECK_LT(index, num_bits_); 104 DCHECK_LT(index, num_bits_);
105 DCHECK_GE(index, 0); 105 DCHECK_GE(index, 0);
106 const int i = index & (kIntBits-1); 106 const int i = index & (kIntBits-1);
107 const int j = index / kIntBits; 107 const int j = index / kIntBits;
108 return map_[j] & (1 << i) ? true : false; 108 return ((map_[j] & (1 << i)) != 0);
109 } 109 }
110 110
111 void Bitmap::Toggle(int index) { 111 void Bitmap::Toggle(int index) {
112 DCHECK_LT(index, num_bits_); 112 DCHECK_LT(index, num_bits_);
113 DCHECK_GE(index, 0); 113 DCHECK_GE(index, 0);
114 const int i = index & (kIntBits - 1); 114 const int i = index & (kIntBits - 1);
115 const int j = index / kIntBits; 115 const int j = index / kIntBits;
116 map_[j] ^= (1 << i); 116 map_[j] ^= (1 << i);
117 } 117 }
118 118
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 uint32 to_add = 0xffffffff << len; 302 uint32 to_add = 0xffffffff << len;
303 to_add = (~to_add) << offset; 303 to_add = (~to_add) << offset;
304 if (value) { 304 if (value) {
305 map_[word] |= to_add; 305 map_[word] |= to_add;
306 } else { 306 } else {
307 map_[word] &= ~to_add; 307 map_[word] &= ~to_add;
308 } 308 }
309 } 309 }
310 310
311 } // namespace disk_cache 311 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/base/escape.cc ('k') | net/disk_cache/entry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698