Commit e2d6b60d authored by Shubham Aggarwal's avatar Shubham Aggarwal Committed by Commit Bot

sql: Move defaults from Database constructor to member declaration

We prefer having constant default values to be listed alongside the data
member declaration instead of in the constructor.

This is a purely stylistic change and should not have any functional
effect.

Change-Id: If4ad7be6e73ff52e92258452fe86a7b3a7f790b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490860Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819698}
parent 85b41d76
...@@ -240,17 +240,7 @@ static_assert(DatabaseOptions::kDefaultPageSize == SQLITE_DEFAULT_PAGE_SIZE, ...@@ -240,17 +240,7 @@ static_assert(DatabaseOptions::kDefaultPageSize == SQLITE_DEFAULT_PAGE_SIZE,
Database::Database() : Database({.exclusive_locking = false}) {} Database::Database() : Database({.exclusive_locking = false}) {}
Database::Database(DatabaseOptions options) Database::Database(DatabaseOptions options)
: db_(nullptr), : options_(options), mmap_disabled_(!enable_mmap_by_default_) {
options_(options),
transaction_nesting_(0),
needs_rollback_(false),
in_memory_(false),
poisoned_(false),
mmap_alt_status_(false),
mmap_disabled_(!enable_mmap_by_default_),
mmap_enabled_(false),
total_changes_at_last_release_(0),
stats_histogram_(nullptr) {
DCHECK_GE(options.page_size, 512); DCHECK_GE(options.page_size, 512);
DCHECK_LE(options.page_size, 65536); DCHECK_LE(options.page_size, 65536);
DCHECK(!(options.page_size & (options.page_size - 1))) DCHECK(!(options.page_size & (options.page_size - 1)))
......
...@@ -779,7 +779,7 @@ class COMPONENT_EXPORT(SQL) Database { ...@@ -779,7 +779,7 @@ class COMPONENT_EXPORT(SQL) Database {
// The actual sqlite database. Will be null before Init has been called or if // The actual sqlite database. Will be null before Init has been called or if
// Init resulted in an error. // Init resulted in an error.
sqlite3* db_; sqlite3* db_ = nullptr;
// TODO(shuagga@microsoft.com): Make `options_` const after removing all // TODO(shuagga@microsoft.com): Make `options_` const after removing all
// setters. // setters.
...@@ -798,36 +798,36 @@ class COMPONENT_EXPORT(SQL) Database { ...@@ -798,36 +798,36 @@ class COMPONENT_EXPORT(SQL) Database {
std::set<StatementRef*> open_statements_; std::set<StatementRef*> open_statements_;
// Number of currently-nested transactions. // Number of currently-nested transactions.
int transaction_nesting_; int transaction_nesting_ = 0;
// True if any of the currently nested transactions have been rolled back. // True if any of the currently nested transactions have been rolled back.
// When we get to the outermost transaction, this will determine if we do // When we get to the outermost transaction, this will determine if we do
// a rollback instead of a commit. // a rollback instead of a commit.
bool needs_rollback_; bool needs_rollback_ = false;
// True if database is open with OpenInMemory(), False if database is open // True if database is open with OpenInMemory(), False if database is open
// with Open(). // with Open().
bool in_memory_; bool in_memory_ = false;
// |true| if the Database was closed using RazeAndClose(). Used // |true| if the Database was closed using RazeAndClose(). Used
// to enable diagnostics to distinguish calls to never-opened // to enable diagnostics to distinguish calls to never-opened
// databases (incorrect use of the API) from calls to once-valid // databases (incorrect use of the API) from calls to once-valid
// databases. // databases.
bool poisoned_; bool poisoned_ = false;
// |true| to use alternate storage for tracking mmap status. // |true| to use alternate storage for tracking mmap status.
bool mmap_alt_status_; bool mmap_alt_status_ = false;
// |true| if SQLite memory-mapped I/O is not desired for this database. // |true| if SQLite memory-mapped I/O is not desired for this database.
bool mmap_disabled_; bool mmap_disabled_;
// |true| if SQLite memory-mapped I/O was enabled for this database. // |true| if SQLite memory-mapped I/O was enabled for this database.
// Used by ReleaseCacheMemoryIfNeeded(). // Used by ReleaseCacheMemoryIfNeeded().
bool mmap_enabled_; bool mmap_enabled_ = false;
// Used by ReleaseCacheMemoryIfNeeded() to track if new changes have happened // Used by ReleaseCacheMemoryIfNeeded() to track if new changes have happened
// since memory was last released. // since memory was last released.
int total_changes_at_last_release_; int total_changes_at_last_release_ = 0;
ErrorCallback error_callback_; ErrorCallback error_callback_;
...@@ -835,7 +835,7 @@ class COMPONENT_EXPORT(SQL) Database { ...@@ -835,7 +835,7 @@ class COMPONENT_EXPORT(SQL) Database {
std::string histogram_tag_; std::string histogram_tag_;
// Linear histogram for RecordEvent(). // Linear histogram for RecordEvent().
base::HistogramBase* stats_histogram_; base::HistogramBase* stats_histogram_ = nullptr;
// Stores the dump provider object when db is open. // Stores the dump provider object when db is open.
std::unique_ptr<DatabaseMemoryDumpProvider> memory_dump_provider_; std::unique_ptr<DatabaseMemoryDumpProvider> memory_dump_provider_;
......
...@@ -55,7 +55,7 @@ void RecordDeprecationEvent(DeprecationEventType deprecation_event) { ...@@ -55,7 +55,7 @@ void RecordDeprecationEvent(DeprecationEventType deprecation_event) {
namespace sql { namespace sql {
MetaTable::MetaTable() : db_(nullptr) {} MetaTable::MetaTable() = default;
MetaTable::~MetaTable() = default; MetaTable::~MetaTable() = default;
......
...@@ -113,7 +113,7 @@ class COMPONENT_EXPORT(SQL) MetaTable { ...@@ -113,7 +113,7 @@ class COMPONENT_EXPORT(SQL) MetaTable {
void PrepareSetStatement(Statement* statement, const char* key); void PrepareSetStatement(Statement* statement, const char* key);
bool PrepareGetStatement(Statement* statement, const char* key); bool PrepareGetStatement(Statement* statement, const char* key);
Database* db_; Database* db_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(MetaTable); DISALLOW_COPY_AND_ASSIGN(MetaTable);
}; };
......
...@@ -22,12 +22,10 @@ namespace sql { ...@@ -22,12 +22,10 @@ namespace sql {
Statement::Statement() Statement::Statement()
: ref_(base::MakeRefCounted<Database::StatementRef>(nullptr, : ref_(base::MakeRefCounted<Database::StatementRef>(nullptr,
nullptr, nullptr,
false)), false)) {}
stepped_(false),
succeeded_(false) {}
Statement::Statement(scoped_refptr<Database::StatementRef> ref) Statement::Statement(scoped_refptr<Database::StatementRef> ref)
: ref_(std::move(ref)), stepped_(false), succeeded_(false) {} : ref_(std::move(ref)) {}
Statement::~Statement() { Statement::~Statement() {
// Free the resources associated with this statement. We assume there's only // Free the resources associated with this statement. We assume there's only
......
...@@ -190,10 +190,10 @@ class COMPONENT_EXPORT(SQL) Statement { ...@@ -190,10 +190,10 @@ class COMPONENT_EXPORT(SQL) Statement {
// Set after Step() or Run() are called, reset by Reset(). Used to // Set after Step() or Run() are called, reset by Reset(). Used to
// prevent accidental calls to API functions which would not work // prevent accidental calls to API functions which would not work
// correctly after stepping has started. // correctly after stepping has started.
bool stepped_; bool stepped_ = false;
// See Succeeded() for what this holds. // See Succeeded() for what this holds.
bool succeeded_; bool succeeded_ = false;
DISALLOW_COPY_AND_ASSIGN(Statement); DISALLOW_COPY_AND_ASSIGN(Statement);
}; };
......
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
namespace sql { namespace sql {
Transaction::Transaction(Database* database) Transaction::Transaction(Database* database) : database_(database) {}
: database_(database), is_open_(false) {}
Transaction::~Transaction() { Transaction::~Transaction() {
if (is_open_) if (is_open_)
......
...@@ -50,7 +50,7 @@ class COMPONENT_EXPORT(SQL) Transaction { ...@@ -50,7 +50,7 @@ class COMPONENT_EXPORT(SQL) Transaction {
// True when the transaction is open, false when it's already been committed // True when the transaction is open, false when it's already been committed
// or rolled back. // or rolled back.
bool is_open_; bool is_open_ = false;
DISALLOW_COPY_AND_ASSIGN(Transaction); DISALLOW_COPY_AND_ASSIGN(Transaction);
}; };
......
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