Skip to content

Commit

Permalink
mutation_partition: Pass schema by const& where applicable
Browse files Browse the repository at this point in the history
If method doesn't want to share schema ownership it doesn't have to
take it by shared pointer. The benefit is that it's slightly cheaper
and those methods may now be called from places which don't own
schema.
  • Loading branch information
tgrabiec committed May 13, 2015
1 parent a5ff381 commit 56bea44
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion cql3/statements/delete_statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace statements {

void delete_statement::add_update_for_key(mutation& m, const exploded_clustering_prefix& prefix, const update_parameters& params) {
if (_column_operations.empty()) {
m.partition().apply_delete(s, prefix, params.make_tombstone());
m.partition().apply_delete(*s, prefix, params.make_tombstone());
return;
}

Expand Down
8 changes: 4 additions & 4 deletions database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ column_family::find_partition(const dht::decorated_key& key) const {
for (auto&& mt : _memtables) {
auto mp = mt.find_partition(key);
if (mp) {
ret.apply(_schema, *mp);
ret.apply(*_schema, *mp);
any = true;
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ column_family::for_all_partitions(Func&& func) const {
}
if (current) {
// FIXME: handle different schemas
current->second.apply(_schema, mp);
current->second.apply(*_schema, mp);
} else {
current = std::make_pair(key, mp);
}
Expand Down Expand Up @@ -555,13 +555,13 @@ database::find_or_create_keyspace(const sstring& name) {
void
memtable::apply(const mutation& m) {
mutation_partition& p = find_or_create_partition(m.decorated_key());
p.apply(_schema, m.partition());
p.apply(*_schema, m.partition());
}

void
memtable::apply(const frozen_mutation& m) {
mutation_partition& p = find_or_create_partition_slow(m.key(*_schema));
p.apply(_schema, m.partition());
p.apply(*_schema, m.partition());
}

// Based on:
Expand Down
38 changes: 19 additions & 19 deletions mutation_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ mutation_partition::operator=(const mutation_partition& x) {
}

void
mutation_partition::apply(schema_ptr schema, const mutation_partition& p) {
mutation_partition::apply(const schema& schema, const mutation_partition& p) {
_tombstone.apply(p._tombstone);

for (auto&& e : p._row_tombstones) {
apply_row_tombstone(*schema, e.prefix(), e.t());
apply_row_tombstone(schema, e.prefix(), e.t());
}

auto merge_cells = [this, schema] (row& old_row, const row& new_row, auto&& find_column_def) {
static auto merge_cells = [] (row& old_row, const row& new_row, auto&& find_column_def) {
for (auto&& new_column : new_row) {
auto col = new_column.first;
auto i = old_row.find(col);
Expand All @@ -49,14 +49,14 @@ mutation_partition::apply(schema_ptr schema, const mutation_partition& p) {
}
};

auto find_static_column_def = [schema] (auto col) -> const column_definition& { return schema->static_column_at(col); };
auto find_regular_column_def = [schema] (auto col) -> const column_definition& { return schema->regular_column_at(col); };
auto find_static_column_def = [&schema] (auto col) -> const column_definition& { return schema.static_column_at(col); };
auto find_regular_column_def = [&schema] (auto col) -> const column_definition& { return schema.regular_column_at(col); };

merge_cells(_static_row, p._static_row, find_static_column_def);

for (auto&& entry : p._rows) {
auto& key = entry.key();
auto i = _rows.find(key, rows_entry::compare(*schema));
auto i = _rows.find(key, rows_entry::compare(schema));
if (i == _rows.end()) {
auto e = new rows_entry(entry);
_rows.insert(i, *e);
Expand All @@ -69,9 +69,9 @@ mutation_partition::apply(schema_ptr schema, const mutation_partition& p) {
}

void
mutation_partition::apply(schema_ptr schema, mutation_partition_view p) {
mutation_partition_applier applier(*schema, *this);
p.accept(*schema, applier);
mutation_partition::apply(const schema& schema, mutation_partition_view p) {
mutation_partition_applier applier(schema, *this);
p.accept(schema, applier);
}

tombstone
Expand Down Expand Up @@ -128,24 +128,24 @@ mutation_partition::apply_row_tombstone(const schema& schema, clustering_key_pre
}

void
mutation_partition::apply_delete(schema_ptr schema, const exploded_clustering_prefix& prefix, tombstone t) {
mutation_partition::apply_delete(const schema& schema, const exploded_clustering_prefix& prefix, tombstone t) {
if (!prefix) {
apply(t);
} else if (prefix.is_full(*schema)) {
apply_delete(schema, clustering_key::from_clustering_prefix(*schema, prefix), t);
} else if (prefix.is_full(schema)) {
apply_delete(schema, clustering_key::from_clustering_prefix(schema, prefix), t);
} else {
apply_row_tombstone(*schema, clustering_key_prefix::from_clustering_prefix(*schema, prefix), t);
apply_row_tombstone(schema, clustering_key_prefix::from_clustering_prefix(schema, prefix), t);
}
}

void
mutation_partition::apply_delete(schema_ptr schema, clustering_key&& key, tombstone t) {
clustered_row(*schema, std::move(key)).apply(t);
mutation_partition::apply_delete(const schema& schema, clustering_key&& key, tombstone t) {
clustered_row(schema, std::move(key)).apply(t);
}

void
mutation_partition::apply_delete(schema_ptr schema, clustering_key_view key, tombstone t) {
clustered_row(*schema, key).apply(t);
mutation_partition::apply_delete(const schema& schema, clustering_key_view key, tombstone t) {
clustered_row(schema, key).apply(t);
}

void
Expand All @@ -154,8 +154,8 @@ mutation_partition::apply_insert(const schema& s, clustering_key_view key, api::
}

const rows_entry*
mutation_partition::find_entry(schema_ptr schema, const clustering_key_prefix& key) const {
auto i = _rows.find(key, rows_entry::key_comparator(clustering_key::less_compare_with_prefix(*schema)));
mutation_partition::find_entry(const schema& schema, const clustering_key_prefix& key) const {
auto i = _rows.find(key, rows_entry::key_comparator(clustering_key::less_compare_with_prefix(schema)));
if (i == _rows.end()) {
return nullptr;
}
Expand Down
12 changes: 6 additions & 6 deletions mutation_partition.hh
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ public:
friend std::ostream& operator<<(std::ostream& os, const mutation_partition& mp);
public:
void apply(tombstone t) { _tombstone.apply(t); }
void apply_delete(schema_ptr schema, const exploded_clustering_prefix& prefix, tombstone t);
void apply_delete(schema_ptr schema, clustering_key&& key, tombstone t);
void apply_delete(schema_ptr schema, clustering_key_view key, tombstone t);
void apply_delete(const schema& schema, const exploded_clustering_prefix& prefix, tombstone t);
void apply_delete(const schema& schema, clustering_key&& key, tombstone t);
void apply_delete(const schema& schema, clustering_key_view key, tombstone t);
// Equivalent to applying a mutation with an empty row, created with given timestamp
void apply_insert(const schema& s, clustering_key_view, api::timestamp_type created_at);
// prefix must not be full
void apply_row_tombstone(const schema& schema, clustering_key_prefix prefix, tombstone t);
void apply(schema_ptr schema, const mutation_partition& p);
void apply(schema_ptr schema, mutation_partition_view);
void apply(const schema& schema, const mutation_partition& p);
void apply(const schema& schema, mutation_partition_view);
public:
deletable_row& clustered_row(const clustering_key& key);
deletable_row& clustered_row(clustering_key&& key);
Expand All @@ -225,7 +225,7 @@ public:
const rows_type& clustered_rows() const { return _rows; }
const row_tombstones_type& row_tombstones() const { return _row_tombstones; }
const row* find_row(const clustering_key& key) const;
const rows_entry* find_entry(schema_ptr schema, const clustering_key_prefix& key) const;
const rows_entry* find_entry(const schema& schema, const clustering_key_prefix& key) const;
tombstone range_tombstone_for_row(const schema& schema, const clustering_key& key) const;
tombstone tombstone_for_row(const schema& schema, const clustering_key& key) const;
tombstone tombstone_for_row(const schema& schema, const rows_entry& e) const;
Expand Down
14 changes: 7 additions & 7 deletions tests/urchin/frozen_mutation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ BOOST_AUTO_TEST_CASE(test_writing_and_reading) {

test_freezing(m);

m.partition().apply_delete(s, ck2, new_tombstone());
m.partition().apply_delete(*s, ck2, new_tombstone());

test_freezing(m);

Expand Down Expand Up @@ -107,16 +107,16 @@ BOOST_AUTO_TEST_CASE(test_application_of_partition_view_has_the_same_effect_as_a
m2.set_static_cell("static_1", bytes("val5"), new_timestamp());

mutation m_frozen(key, s);
m_frozen.partition().apply(s, freeze(m1).partition());
m_frozen.partition().apply(s, freeze(m2).partition());
m_frozen.partition().apply(*s, freeze(m1).partition());
m_frozen.partition().apply(*s, freeze(m2).partition());

mutation m_unfrozen(key, s);
m_unfrozen.partition().apply(s, m1.partition());
m_unfrozen.partition().apply(s, m2.partition());
m_unfrozen.partition().apply(*s, m1.partition());
m_unfrozen.partition().apply(*s, m2.partition());

mutation m_refrozen(key, s);
m_refrozen.partition().apply(s, freeze(m1).unfreeze(s).partition());
m_refrozen.partition().apply(s, freeze(m2).unfreeze(s).partition());
m_refrozen.partition().apply(*s, freeze(m1).unfreeze(s).partition());
m_refrozen.partition().apply(*s, freeze(m2).unfreeze(s).partition());

assert_that(m_unfrozen).is_equal_to(m_refrozen);
assert_that(m_unfrozen).is_equal_to(m_frozen);
Expand Down

0 comments on commit 56bea44

Please sign in to comment.