Make printer profile swithing faster (#14437)

* Fix issue that switching printer profile is slow.
`wxGetApp().get_tab(preset_type)->select_preset(preset_name);` is called twice when switching printer profiles. Only one needed.

* Avoid unnecessary type conversion & function call during printer profile switching:
- Don't call `config->opt_string("printer_model")` repeatedly
- Use ref when possible during iterating
- Avoid unnecessary `wxString` to `std::string` conversion
This commit is contained in:
Noisyfox
2026-07-13 09:52:18 +08:00
committed by GitHub
parent 78692aa08f
commit 6a254c35d4
3 changed files with 16 additions and 15 deletions

View File

@@ -890,12 +890,11 @@ std::string Preset::get_printer_type(PresetBundle *preset_bundle)
{
if (preset_bundle) {
auto config = &preset_bundle->printers.get_edited_preset().config;
std::string vendor_name;
for (auto vendor_profile : preset_bundle->vendors) {
for (auto vendor_model : vendor_profile.second.models)
if (vendor_model.name == config->opt_string("printer_model"))
const auto& printer_model = config->opt_string("printer_model");
for (const auto& vendor_profile : preset_bundle->vendors) {
for (const auto& vendor_model : vendor_profile.second.models)
if (vendor_model.name == printer_model)
{
vendor_name = vendor_profile.first;
return vendor_model.model_id;
}
}
@@ -907,11 +906,10 @@ std::string Preset::get_current_printer_type(PresetBundle *preset_bundle)
{
if (preset_bundle) {
auto config = &(this->config);
std::string vendor_name;
for (auto vendor_profile : preset_bundle->vendors) {
for (auto vendor_model : vendor_profile.second.models)
if (vendor_model.name == config->opt_string("printer_model")) {
vendor_name = vendor_profile.first;
const auto& printer_model = config->opt_string("printer_model");
for (const auto& vendor_profile : preset_bundle->vendors) {
for (const auto& vendor_model : vendor_profile.second.models)
if (vendor_model.name == printer_model) {
return vendor_model.model_id;
}
}