Commit 4e4c7e98 authored by jsbell's avatar jsbell Committed by Commit bot

IndexedDB: Use C++11 in-class member initializers

Remove some redundant number_(0) initializers.

Also, for IndexedDBKey, use number_ for both number and date type
to save memory.

R=cmumford@chromium.org

Review URL: https://codereview.chromium.org/1071683002

Cr-Commit-Position: refs/heads/master@{#324347}
parent 68c68147
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "content/common/indexed_db/indexed_db_key.h" #include "content/common/indexed_db/indexed_db_key.h"
#include <string> #include <string>
#include "base/logging.h"
namespace content { namespace content {
...@@ -56,18 +55,15 @@ static IndexedDBKey::KeyArray CopyKeyArray(const T& array) { ...@@ -56,18 +55,15 @@ static IndexedDBKey::KeyArray CopyKeyArray(const T& array) {
IndexedDBKey::IndexedDBKey() IndexedDBKey::IndexedDBKey()
: type_(WebIDBKeyTypeNull), : type_(WebIDBKeyTypeNull),
date_(0),
number_(0),
size_estimate_(kOverheadSize) {} size_estimate_(kOverheadSize) {}
IndexedDBKey::IndexedDBKey(WebIDBKeyType type) IndexedDBKey::IndexedDBKey(WebIDBKeyType type)
: type_(type), date_(0), number_(0), size_estimate_(kOverheadSize) { : type_(type), size_estimate_(kOverheadSize) {
DCHECK(type == WebIDBKeyTypeNull || type == WebIDBKeyTypeInvalid); DCHECK(type == WebIDBKeyTypeNull || type == WebIDBKeyTypeInvalid);
} }
IndexedDBKey::IndexedDBKey(double number, WebIDBKeyType type) IndexedDBKey::IndexedDBKey(double number, WebIDBKeyType type)
: type_(type), : type_(type),
date_(number),
number_(number), number_(number),
size_estimate_(kOverheadSize + sizeof(number)) { size_estimate_(kOverheadSize + sizeof(number)) {
DCHECK(type == WebIDBKeyTypeNumber || type == WebIDBKeyTypeDate); DCHECK(type == WebIDBKeyTypeNumber || type == WebIDBKeyTypeDate);
...@@ -76,8 +72,6 @@ IndexedDBKey::IndexedDBKey(double number, WebIDBKeyType type) ...@@ -76,8 +72,6 @@ IndexedDBKey::IndexedDBKey(double number, WebIDBKeyType type)
IndexedDBKey::IndexedDBKey(const KeyArray& array) IndexedDBKey::IndexedDBKey(const KeyArray& array)
: type_(WebIDBKeyTypeArray), : type_(WebIDBKeyTypeArray),
array_(CopyKeyArray(array)), array_(CopyKeyArray(array)),
date_(0),
number_(0),
size_estimate_(kOverheadSize + CalculateArraySize(array)) {} size_estimate_(kOverheadSize + CalculateArraySize(array)) {}
IndexedDBKey::IndexedDBKey(const std::string& binary) IndexedDBKey::IndexedDBKey(const std::string& binary)
...@@ -137,7 +131,6 @@ int IndexedDBKey::CompareTo(const IndexedDBKey& other) const { ...@@ -137,7 +131,6 @@ int IndexedDBKey::CompareTo(const IndexedDBKey& other) const {
case WebIDBKeyTypeString: case WebIDBKeyTypeString:
return string_.compare(other.string_); return string_.compare(other.string_);
case WebIDBKeyTypeDate: case WebIDBKeyTypeDate:
return Compare(date_, other.date_);
case WebIDBKeyTypeNumber: case WebIDBKeyTypeNumber:
return Compare(number_, other.number_); return Compare(number_, other.number_);
case WebIDBKeyTypeInvalid: case WebIDBKeyTypeInvalid:
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <vector> #include <vector>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/logging.h"
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
...@@ -41,11 +42,26 @@ class CONTENT_EXPORT IndexedDBKey { ...@@ -41,11 +42,26 @@ class CONTENT_EXPORT IndexedDBKey {
bool Equals(const IndexedDBKey& other) const; bool Equals(const IndexedDBKey& other) const;
blink::WebIDBKeyType type() const { return type_; } blink::WebIDBKeyType type() const { return type_; }
const std::vector<IndexedDBKey>& array() const { return array_; } const std::vector<IndexedDBKey>& array() const {
const std::string& binary() const { return binary_; } DCHECK_EQ(type_, blink::WebIDBKeyTypeArray);
const base::string16& string() const { return string_; } return array_;
double date() const { return date_; } }
double number() const { return number_; } const std::string& binary() const {
DCHECK_EQ(type_, blink::WebIDBKeyTypeBinary);
return binary_;
}
const base::string16& string() const {
DCHECK_EQ(type_, blink::WebIDBKeyTypeString);
return string_;
}
double date() const {
DCHECK_EQ(type_, blink::WebIDBKeyTypeDate);
return number_;
}
double number() const {
DCHECK_EQ(type_, blink::WebIDBKeyTypeNumber);
return number_;
}
size_t size_estimate() const { return size_estimate_; } size_t size_estimate() const { return size_estimate_; }
...@@ -56,8 +72,7 @@ class CONTENT_EXPORT IndexedDBKey { ...@@ -56,8 +72,7 @@ class CONTENT_EXPORT IndexedDBKey {
std::vector<IndexedDBKey> array_; std::vector<IndexedDBKey> array_;
std::string binary_; std::string binary_;
base::string16 string_; base::string16 string_;
double date_; double number_ = 0;
double number_;
size_t size_estimate_; size_t size_estimate_;
}; };
......
...@@ -9,11 +9,7 @@ ...@@ -9,11 +9,7 @@
namespace content { namespace content {
IndexedDBKeyRange::IndexedDBKeyRange() IndexedDBKeyRange::IndexedDBKeyRange() = default;
: lower_(blink::WebIDBKeyTypeNull),
upper_(blink::WebIDBKeyTypeNull),
lower_open_(false),
upper_open_(false) {}
IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKey& lower, IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKey& lower,
const IndexedDBKey& upper, const IndexedDBKey& upper,
...@@ -25,7 +21,8 @@ IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKey& lower, ...@@ -25,7 +21,8 @@ IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKey& lower,
upper_open_(upper_open) {} upper_open_(upper_open) {}
IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKey& key) IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKey& key)
: lower_(key), upper_(key), lower_open_(false), upper_open_(false) {} : lower_(key), upper_(key) {
}
IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKeyRange& other) = default; IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKeyRange& other) = default;
IndexedDBKeyRange::~IndexedDBKeyRange() = default; IndexedDBKeyRange::~IndexedDBKeyRange() = default;
......
...@@ -31,10 +31,10 @@ class CONTENT_EXPORT IndexedDBKeyRange { ...@@ -31,10 +31,10 @@ class CONTENT_EXPORT IndexedDBKeyRange {
bool IsOnlyKey() const; bool IsOnlyKey() const;
private: private:
IndexedDBKey lower_; IndexedDBKey lower_ = IndexedDBKey(blink::WebIDBKeyTypeNull);
IndexedDBKey upper_; IndexedDBKey upper_ = IndexedDBKey(blink::WebIDBKeyTypeNull);
bool lower_open_; bool lower_open_ = false;
bool upper_open_; bool upper_open_ = false;
}; };
} // namespace content } // namespace content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment