Refactor base/bitarray.h
This is just a code refactoring of base/bitarray.h. No behavior change is intended.
BUG=none
TEST=unittest
git-svn-id: https://mozc.googlecode.com/svn/trunk@534 a6090854-d499-a067-5803-1114d4e51264
diff --git a/src/base/bitarray.h b/src/base/bitarray.h
index 785b73e..fca6e5b 100644
--- a/src/base/bitarray.h
+++ b/src/base/bitarray.h
@@ -30,56 +30,55 @@
#ifndef MOZC_BASE_BITARRAY_H_
#define MOZC_BASE_BITARRAY_H_
-#include <string.h> // memset
+#include <cstring> // memset
+
#include "base/port.h"
+#include "base/scoped_ptr.h"
namespace mozc {
class BitArray {
public:
// Specify the size of bit vector
- explicit BitArray(uint32 size)
- : array_(new uint32[1 + (size >> 5)]), size_(size) {
- memset(reinterpret_cast<char *>(array_), 0, 4 * (1 + (size >> 5)));
+ explicit BitArray(uint32 size) : array_(new uint32[1 + (size >> 5)]),
+ size_(size) {
+ memset(reinterpret_cast<char *>(array_.get()), 0, 4 * (1 + (size >> 5)));
}
- ~BitArray() {
- delete [] array_;
- array_ = NULL;
- }
+ ~BitArray() {}
- // get true/false of |index|
- inline bool get(uint32 index) const {
+ // Gets true/false of |index|
+ bool get(uint32 index) const {
return static_cast<bool>(
(array_[(index >> 5)] >> (index & 0x0000001F)) & 0x00000001);
}
- // set |index| as true
- inline void set(uint32 index) {
+ // Sets the bit at |index| to true.
+ void set(uint32 index) {
array_[(index >> 5)] |= 0x00000001 << (index & 0x0000001F);
}
- // set |index| as false
- inline void clear(uint32 index) {
+ // Sets the bit at |index| to false.
+ void clear(uint32 index) {
array_[(index >> 5)] &= ~(0x00000001 << (index & 0x0000001F));
}
- // return the body of bit vector
+ // Returns the body of bit vector.
const char *array() const {
- return reinterpret_cast<const char *>(array_);
+ return reinterpret_cast<const char *>(array_.get());
}
- // return the required buffer size for saving the bit vector
+ // Returns the required buffer size for saving the bit vector.
size_t array_size() const {
return 4 * (1 + (size_ >> 5));
}
- // return number of bit(s)
+ // Returns the number of bit(s).
size_t size() const {
return size_;
}
- // immutable acessor
+ // Immutable accessor.
static bool GetValue(const char *array, uint32 index) {
const uint32 *uarray = reinterpret_cast<const uint32 *>(array);
return static_cast<bool>(
@@ -87,8 +86,12 @@
}
private:
- uint32 *array_;
- size_t size_;
+ scoped_ptr<uint32[]> array_;
+ const size_t size_;
+
+ DISALLOW_COPY_AND_ASSIGN(BitArray);
};
+
} // namespace mozc
+
#endif // MOZC_BASE_BITARRAY_H_
diff --git a/src/mozc_version_template.txt b/src/mozc_version_template.txt
index c13ebc4..acbef16 100644
--- a/src/mozc_version_template.txt
+++ b/src/mozc_version_template.txt
@@ -1,6 +1,6 @@
MAJOR=2
MINOR=16
-BUILD=2050
+BUILD=2051
REVISION=102
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
# downloaded by NaCl Mozc.