summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/bitmap.cc
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-21 23:46:49 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-21 23:46:49 +0000
commit7aefb155470efae35c224f1ebb21f5ff893179f5 (patch)
tree6333871e5b8fdcfcafadefc95457e480c23fb8ad /net/disk_cache/bitmap.cc
parent9c678e93d80ab8ed8f52043e1096e2d08f97980e (diff)
downloadchromium_src-7aefb155470efae35c224f1ebb21f5ff893179f5.zip
chromium_src-7aefb155470efae35c224f1ebb21f5ff893179f5.tar.gz
chromium_src-7aefb155470efae35c224f1ebb21f5ff893179f5.tar.bz2
More net/ header/implementation method reordering.
(Contains some minor de-inlining.) BUG=68682 TEST=compiles Review URL: http://codereview.chromium.org/6263010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72232 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/bitmap.cc')
-rw-r--r--net/disk_cache/bitmap.cc63
1 files changed, 45 insertions, 18 deletions
diff --git a/net/disk_cache/bitmap.cc b/net/disk_cache/bitmap.cc
index e025090..6c9aceb 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