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 @@
#include "content/common/indexed_db/indexed_db_key.h"
#include <string>
#include "base/logging.h"
namespace content {
......@@ -56,18 +55,15 @@ static IndexedDBKey::KeyArray CopyKeyArray(const T& array) {
IndexedDBKey::IndexedDBKey()
: type_(WebIDBKeyTypeNull),
date_(0),
number_(0),
size_estimate_(kOverheadSize) {}
IndexedDBKey::IndexedDBKey(WebIDBKeyType type)
: type_(type), date_(0), number_(0), size_estimate_(kOverheadSize) {
: type_(type), size_estimate_(kOverheadSize) {
DCHECK(type == WebIDBKeyTypeNull || type == WebIDBKeyTypeInvalid);
}
IndexedDBKey::IndexedDBKey(double number, WebIDBKeyType type)
: type_(type),
date_(number),
number_(number),
size_estimate_(kOverheadSize + sizeof(number)) {
DCHECK(type == WebIDBKeyTypeNumber || type == WebIDBKeyTypeDate);
......@@ -76,8 +72,6 @@ IndexedDBKey::IndexedDBKey(double number, WebIDBKeyType type)
IndexedDBKey::IndexedDBKey(const KeyArray& array)
: type_(WebIDBKeyTypeArray),
array_(CopyKeyArray(array)),
date_(0),
number_(0),
size_estimate_(kOverheadSize + CalculateArraySize(array)) {}
IndexedDBKey::IndexedDBKey(const std::string& binary)
......@@ -137,7 +131,6 @@ int IndexedDBKey::CompareTo(const IndexedDBKey& other) const {
case WebIDBKeyTypeString:
return string_.compare(other.string_);
case WebIDBKeyTypeDate:
return Compare(date_, other.date_);
case WebIDBKeyTypeNumber:
return Compare(number_, other.number_);
case WebIDBKeyTypeInvalid:
......
......@@ -9,6 +9,7 @@
#include <vector>
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/memory/scoped_vector.h"
#include "base/strings/string16.h"
#include "content/common/content_export.h"
......@@ -41,11 +42,26 @@ class CONTENT_EXPORT IndexedDBKey {
bool Equals(const IndexedDBKey& other) const;
blink::WebIDBKeyType type() const { return type_; }
const std::vector<IndexedDBKey>& array() const { return array_; }
const std::string& binary() const { return binary_; }
const base::string16& string() const { return string_; }
double date() const { return date_; }
double number() const { return number_; }
const std::vector<IndexedDBKey>& array() const {
DCHECK_EQ(type_, blink::WebIDBKeyTypeArray);
return array_;
}
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_; }
......@@ -56,8 +72,7 @@ class CONTENT_EXPORT IndexedDBKey {
std::vector<IndexedDBKey> array_;
std::string binary_;
base::string16 string_;
double date_;
double number_;
double number_ = 0;
size_t size_estimate_;
};
......
......@@ -9,11 +9,7 @@
namespace content {
IndexedDBKeyRange::IndexedDBKeyRange()
: lower_(blink::WebIDBKeyTypeNull),
upper_(blink::WebIDBKeyTypeNull),
lower_open_(false),
upper_open_(false) {}
IndexedDBKeyRange::IndexedDBKeyRange() = default;
IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKey& lower,
const IndexedDBKey& upper,
......@@ -25,7 +21,8 @@ IndexedDBKeyRange::IndexedDBKeyRange(const IndexedDBKey& lower,
upper_open_(upper_open) {}
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() = default;
......
......@@ -31,10 +31,10 @@ class CONTENT_EXPORT IndexedDBKeyRange {
bool IsOnlyKey() const;
private:
IndexedDBKey lower_;
IndexedDBKey upper_;
bool lower_open_;
bool upper_open_;
IndexedDBKey lower_ = IndexedDBKey(blink::WebIDBKeyTypeNull);
IndexedDBKey upper_ = IndexedDBKey(blink::WebIDBKeyTypeNull);
bool lower_open_ = false;
bool upper_open_ = false;
};
} // 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