Moves shared config and request in setter.

This reduces unnecessary reference counting.

PiperOrigin-RevId: 730718096
This commit is contained in:
Taku Kudo
2025-02-25 05:36:36 +00:00
committed by Hiroyuki Komatsu
parent 206785c5b6
commit e083edab93
9 changed files with 32 additions and 31 deletions

View File

@@ -581,7 +581,8 @@ Composer::Composer()
Composer::Composer(std::shared_ptr<const commands::Request> request, Composer::Composer(std::shared_ptr<const commands::Request> request,
std::shared_ptr<const config::Config> config) std::shared_ptr<const config::Config> config)
: Composer(Table::GetSharedDefaultTable(), request, config) {} : Composer(Table::GetSharedDefaultTable(), std::move(request),
std::move(config)) {}
Composer::Composer(commands::Request request, config::Config config) Composer::Composer(commands::Request request, config::Config config)
: Composer(Table::GetSharedDefaultTable(), std::move(request), : Composer(Table::GetSharedDefaultTable(), std::move(request),
@@ -589,7 +590,7 @@ Composer::Composer(commands::Request request, config::Config config)
Composer::Composer(std::shared_ptr<const Table> table, Composer::Composer(std::shared_ptr<const Table> table,
commands::Request request, config::Config config) commands::Request request, config::Config config)
: Composer(table, : Composer(std::move(table),
std::make_shared<const commands::Request>(std::move(request)), std::make_shared<const commands::Request>(std::move(request)),
std::make_shared<const config::Config>(std::move(config))) {} std::make_shared<const config::Config>(std::move(config))) {}
@@ -602,16 +603,16 @@ Composer::Composer(std::shared_ptr<const Table> table,
comeback_input_mode_(transliteration::HIRAGANA), comeback_input_mode_(transliteration::HIRAGANA),
input_field_type_(commands::Context::NORMAL), input_field_type_(commands::Context::NORMAL),
shifted_sequence_count_(0), shifted_sequence_count_(0),
composition_(table),
max_length_(kMaxPreeditLength), max_length_(kMaxPreeditLength),
request_(request), request_(std::move(request)),
config_(config), config_(std::move(config)),
table_(table), table_(std::move(table)),
composition_(table_),
is_new_input_(true) { is_new_input_(true) {
DCHECK(request_); DCHECK(request_);
DCHECK(config_); DCHECK(config_);
SetInputMode(transliteration::HIRAGANA);
DCHECK(table_); DCHECK(table_);
SetInputMode(transliteration::HIRAGANA);
Reset(); Reset();
} }
@@ -646,19 +647,19 @@ void Composer::ReloadConfig() {
bool Composer::Empty() const { return (GetLength() == 0); } bool Composer::Empty() const { return (GetLength() == 0); }
void Composer::SetTable(std::shared_ptr<const Table> table) { void Composer::SetTable(std::shared_ptr<const Table> table) {
table_ = table; DCHECK(table);
DCHECK(table_); table_ = std::move(table);
composition_.SetTable(table_); composition_.SetTable(table_);
} }
void Composer::SetRequest(std::shared_ptr<const commands::Request> request) { void Composer::SetRequest(std::shared_ptr<const commands::Request> request) {
DCHECK(request); DCHECK(request);
request_ = request; request_ = std::move(request);
} }
void Composer::SetConfig(std::shared_ptr<const config::Config> config) { void Composer::SetConfig(std::shared_ptr<const config::Config> config) {
DCHECK(config); DCHECK(config);
config_ = config; config_ = std::move(config);
} }
void Composer::SetInputMode(transliteration::TransliterationType mode) { void Composer::SetInputMode(transliteration::TransliterationType mode) {

View File

@@ -395,7 +395,6 @@ class Composer final {
commands::Context::InputFieldType input_field_type_; commands::Context::InputFieldType input_field_type_;
size_t shifted_sequence_count_; size_t shifted_sequence_count_;
Composition composition_;
// The original text for the composition. The value is usually // The original text for the composition. The value is usually
// empty, and used for reverse conversion. // empty, and used for reverse conversion.
@@ -414,6 +413,8 @@ class Composer final {
// to use std::shared_ptr for shared object. // to use std::shared_ptr for shared object.
std::shared_ptr<const Table> table_; std::shared_ptr<const Table> table_;
Composition composition_;
// Timestamp of last modified. // Timestamp of last modified.
int64_t timestamp_msec_ = 0; int64_t timestamp_msec_ = 0;

View File

@@ -116,8 +116,6 @@ class ComposerTest : public ::testing::Test {
void TearDown() override { void TearDown() override {
CharacterFormManager::GetCharacterFormManager()->SetDefaultRule(); CharacterFormManager::GetCharacterFormManager()->SetDefaultRule();
composer_.reset();
table_.reset();
} }
std::unique_ptr<Composer> composer_; std::unique_ptr<Composer> composer_;

View File

@@ -113,13 +113,13 @@ bool GetFromPending(const Table *table, const absl::string_view key,
CharChunk::CharChunk(Transliterators::Transliterator transliterator, CharChunk::CharChunk(Transliterators::Transliterator transliterator,
std::shared_ptr<const Table> table) std::shared_ptr<const Table> table)
: table_(table), transliterator_(transliterator) { : table_(std::move(table)), transliterator_(transliterator) {
DCHECK(table_); DCHECK(table_);
DCHECK_NE(transliterator, Transliterators::LOCAL); DCHECK_NE(transliterator, Transliterators::LOCAL);
} }
CharChunk::CharChunk(Transliterators::Transliterator transliterator) CharChunk::CharChunk(Transliterators::Transliterator transliterator)
: table_(Table::GetSharedDefaultTable()), transliterator_(transliterator) { : CharChunk(transliterator, Table::GetSharedDefaultTable()) {
DCHECK_NE(transliterator, Transliterators::LOCAL); DCHECK_NE(transliterator, Transliterators::LOCAL);
} }

View File

@@ -446,8 +446,8 @@ void Composition::SetInputMode(Transliterators::Transliterator transliterator) {
} }
void Composition::SetTable(std::shared_ptr<const Table> table) { void Composition::SetTable(std::shared_ptr<const Table> table) {
table_ = table; DCHECK(table);
DCHECK(table_); table_ = std::move(table);
} }
bool Composition::IsToggleable(size_t position) const { bool Composition::IsToggleable(size_t position) const {

View File

@@ -58,7 +58,8 @@ enum TrimMode {
class Composition final { class Composition final {
public: public:
Composition() = default; Composition() = default;
explicit Composition(std::shared_ptr<const Table> table) : table_(table) { explicit Composition(std::shared_ptr<const Table> table)
: table_(std::move(table)) {
DCHECK(table_); DCHECK(table_);
} }

View File

@@ -121,17 +121,17 @@ EngineConverter::EngineConverter(
segment_index_(0), segment_index_(0),
result_(), result_(),
candidate_list_(true), candidate_list_(true),
request_(request), request_(std::move(request)),
state_(COMPOSITION), state_(COMPOSITION),
request_type_(ConversionRequest::CONVERSION), request_type_(ConversionRequest::CONVERSION),
client_revision_(0), client_revision_(0),
candidate_list_visible_(false) { candidate_list_visible_(false) {
DCHECK(request); DCHECK(request_);
DCHECK(config); DCHECK(config);
conversion_preferences_.use_history = true; conversion_preferences_.use_history = true;
conversion_preferences_.request_suggestion = true; conversion_preferences_.request_suggestion = true;
candidate_list_.set_page_size(request->candidate_page_size()); candidate_list_.set_page_size(request_->candidate_page_size());
SetConfig(config); SetConfig(std::move(config));
} }
bool EngineConverter::CheckState( bool EngineConverter::CheckState(
@@ -1639,13 +1639,13 @@ void EngineConverter::FillIncognitoCandidateWords(
void EngineConverter::SetRequest( void EngineConverter::SetRequest(
std::shared_ptr<const commands::Request> request) { std::shared_ptr<const commands::Request> request) {
DCHECK(request); DCHECK(request);
request_ = request; request_ = std::move(request);
candidate_list_.set_page_size(request_->candidate_page_size()); candidate_list_.set_page_size(request_->candidate_page_size());
} }
void EngineConverter::SetConfig(std::shared_ptr<const config::Config> config) { void EngineConverter::SetConfig(std::shared_ptr<const config::Config> config) {
DCHECK(config); DCHECK(config);
config_ = config; config_ = std::move(config);
updated_command_ = Segment::Candidate::DEFAULT_COMMAND; updated_command_ = Segment::Candidate::DEFAULT_COMMAND;
selection_shortcut_ = config_->selection_shortcut(); selection_shortcut_ = config_->selection_shortcut();
use_cascading_window_ = config_->use_cascading_window(); use_cascading_window_ = config_->use_cascading_window();

View File

@@ -84,7 +84,7 @@ ImeContext::ImeContext(const ImeContext &src) : data_(src.data_) {
void ImeContext::SetRequest(std::shared_ptr<const commands::Request> request) { void ImeContext::SetRequest(std::shared_ptr<const commands::Request> request) {
DCHECK(request); DCHECK(request);
data_.request = request; data_.request = std::move(request);
if (converter_) { if (converter_) {
converter_->SetRequest(data_.request); converter_->SetRequest(data_.request);
} }
@@ -97,7 +97,7 @@ const commands::Request &ImeContext::GetRequest() const {
void ImeContext::SetConfig(std::shared_ptr<const config::Config> config) { void ImeContext::SetConfig(std::shared_ptr<const config::Config> config) {
DCHECK(config); DCHECK(config);
data_.config = config; data_.config = std::move(config);
if (converter_) { if (converter_) {
converter_->SetConfig(data_.config); converter_->SetConfig(data_.config);
@@ -112,7 +112,7 @@ const config::Config &ImeContext::GetConfig() const { return *data_.config; }
void ImeContext::SetKeyMapManager( void ImeContext::SetKeyMapManager(
std::shared_ptr<const keymap::KeyMapManager> key_map_manager) { std::shared_ptr<const keymap::KeyMapManager> key_map_manager) {
DCHECK(key_map_manager); DCHECK(key_map_manager);
data_.key_map_manager = key_map_manager; data_.key_map_manager = std::move(key_map_manager);
} }
const keymap::KeyMapManager &ImeContext::GetKeyMapManager() const { const keymap::KeyMapManager &ImeContext::GetKeyMapManager() const {

View File

@@ -1154,19 +1154,19 @@ void Session::SetTable(std::shared_ptr<const composer::Table> table) {
return; return;
} }
ClearUndoContext(); ClearUndoContext();
context_->mutable_composer()->SetTable(table); context_->mutable_composer()->SetTable(std::move(table));
} }
void Session::SetConfig(std::shared_ptr<const config::Config> config) { void Session::SetConfig(std::shared_ptr<const config::Config> config) {
DCHECK(config); DCHECK(config);
ClearUndoContext(); ClearUndoContext();
context_->SetConfig(config); context_->SetConfig(std::move(config));
} }
void Session::SetRequest(std::shared_ptr<const commands::Request> request) { void Session::SetRequest(std::shared_ptr<const commands::Request> request) {
DCHECK(request); DCHECK(request);
ClearUndoContext(); ClearUndoContext();
context_->SetRequest(request); context_->SetRequest(std::move(request));
} }
void Session::SetKeyMapManager( void Session::SetKeyMapManager(