Optimize parameter passing to avoid unnecessary copying

This commit is contained in:
Pugemon
2024-06-07 04:00:38 +03:00
parent 46ca1bb04a
commit f25a425cb9
123 changed files with 578 additions and 522 deletions
+9 -7
View File
@@ -1,5 +1,7 @@
#include "TextBox.hpp"
#include <utility>
#include "Label.hpp"
#include "../../core/DrawContext.hpp"
#include "../../core/Batch2D.hpp"
@@ -14,7 +16,7 @@ using namespace gui;
TextBox::TextBox(std::wstring placeholder, glm::vec4 padding)
: Panel(glm::vec2(200,32), padding, 0),
input(L""),
placeholder(placeholder)
placeholder(std::move(placeholder))
{
setOnUpPressed(nullptr);
setOnDownPressed(nullptr);
@@ -556,7 +558,7 @@ std::shared_ptr<UINode> TextBox::getAt(glm::vec2 pos, std::shared_ptr<UINode> se
return UINode::getAt(pos, self);
}
void TextBox::setOnUpPressed(runnable callback) {
void TextBox::setOnUpPressed(const runnable &callback) {
if (callback == nullptr) {
onUpPressed = [this]() {
bool shiftPressed = Events::pressed(keycode::LEFT_SHIFT);
@@ -568,7 +570,7 @@ void TextBox::setOnUpPressed(runnable callback) {
}
}
void TextBox::setOnDownPressed(runnable callback) {
void TextBox::setOnDownPressed(const runnable &callback) {
if (callback == nullptr) {
onDownPressed = [this]() {
bool shiftPressed = Events::pressed(keycode::LEFT_SHIFT);
@@ -581,15 +583,15 @@ void TextBox::setOnDownPressed(runnable callback) {
}
void TextBox::setTextSupplier(wstringsupplier supplier) {
this->supplier = supplier;
this->supplier = std::move(supplier);
}
void TextBox::setTextConsumer(wstringconsumer consumer) {
this->consumer = consumer;
this->consumer = std::move(consumer);
}
void TextBox::setTextValidator(wstringchecker validator) {
this->validator = validator;
this->validator = std::move(validator);
}
void TextBox::setFocusedColor(glm::vec4 color) {
@@ -614,7 +616,7 @@ std::wstring TextBox::getText() const {
return input;
}
void TextBox::setText(const std::wstring value) {
void TextBox::setText(const std::wstring& value) {
this->input = value;
input.erase(std::remove(input.begin(), input.end(), '\r'), input.end());
}