| Index: net/disk_cache/bitmap.cc
|
| diff --git a/net/disk_cache/bitmap.cc b/net/disk_cache/bitmap.cc
|
| index e0250909b18732da6f8f3c027d9e4f04ab05e955..6c9aceb05bda46111e0fd6f8cec6bf13244f3b0d 100644
|
| --- a/net/disk_cache/bitmap.cc
|
| +++ b/net/disk_cache/bitmap.cc
|
| @@ -4,6 +4,8 @@
|
|
|
| #include "net/disk_cache/bitmap.h"
|
|
|
| +#include <algorithm>
|
| +
|
| #include "base/logging.h"
|
|
|
| namespace {
|
| @@ -38,6 +40,31 @@ int FindLSBNonEmpty(uint32 word, bool value) {
|
|
|
| namespace disk_cache {
|
|
|
| +Bitmap::Bitmap(int num_bits, bool clear_bits)
|
| + : num_bits_(num_bits),
|
| + array_size_(RequiredArraySize(num_bits)),
|
| + alloc_(true) {
|
| + map_ = new uint32[array_size_];
|
| +
|
| + // Initialize all of the bits.
|
| + if (clear_bits)
|
| + Clear();
|
| +}
|
| +
|
| +Bitmap::Bitmap(uint32* map, int num_bits, int num_words)
|
| + : map_(map),
|
| + num_bits_(num_bits),
|
| + // If size is larger than necessary, trim because array_size_ is used
|
| + // as a bound by various methods.
|
| + array_size_(std::min(RequiredArraySize(num_bits), num_words)),
|
| + alloc_(false) {
|
| +}
|
| +
|
| +Bitmap::~Bitmap() {
|
| + if (alloc_)
|
| + delete [] map_;
|
| +}
|
| +
|
| void Bitmap::Resize(int num_bits, bool clear_bits) {
|
| DCHECK(alloc_ || !map_);
|
| const int old_maxsize = num_bits_;
|
| @@ -105,24 +132,6 @@ void Bitmap::SetMap(const uint32* map, int size) {
|
| memcpy(map_, map, std::min(size, array_size_) * sizeof(*map_));
|
| }
|
|
|
| -void Bitmap::SetWordBits(int start, int len, bool value) {
|
| - DCHECK_LT(len, kIntBits);
|
| - DCHECK_GE(len, 0);
|
| - if (!len)
|
| - return;
|
| -
|
| - int word = start / kIntBits;
|
| - int offset = start % kIntBits;
|
| -
|
| - uint32 to_add = 0xffffffff << len;
|
| - to_add = (~to_add) << offset;
|
| - if (value) {
|
| - map_[word] |= to_add;
|
| - } else {
|
| - map_[word] &= ~to_add;
|
| - }
|
| -}
|
| -
|
| void Bitmap::SetRange(int begin, int end, bool value) {
|
| DCHECK_LE(begin, end);
|
| int start_offset = begin & (kIntBits - 1);
|
| @@ -281,4 +290,22 @@ int Bitmap::FindBits(int* index, int limit, bool value) const {
|
| return end - *index;
|
| }
|
|
|
| +void Bitmap::SetWordBits(int start, int len, bool value) {
|
| + DCHECK_LT(len, kIntBits);
|
| + DCHECK_GE(len, 0);
|
| + if (!len)
|
| + return;
|
| +
|
| + int word = start / kIntBits;
|
| + int offset = start % kIntBits;
|
| +
|
| + uint32 to_add = 0xffffffff << len;
|
| + to_add = (~to_add) << offset;
|
| + if (value) {
|
| + map_[word] |= to_add;
|
| + } else {
|
| + map_[word] &= ~to_add;
|
| + }
|
| +}
|
| +
|
| } // namespace disk_cache
|
|
|