Optimize parameter passing to avoid unnecessary copying
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "../GUI.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <utility>
|
||||
|
||||
using namespace gui;
|
||||
|
||||
@@ -40,9 +41,9 @@ SlotLayout::SlotLayout(
|
||||
position(position),
|
||||
background(background),
|
||||
itemSource(itemSource),
|
||||
updateFunc(updateFunc),
|
||||
shareFunc(shareFunc),
|
||||
rightClick(rightClick) {}
|
||||
updateFunc(std::move(updateFunc)),
|
||||
shareFunc(std::move(shareFunc)),
|
||||
rightClick(std::move(rightClick)) {}
|
||||
|
||||
InventoryBuilder::InventoryBuilder() {
|
||||
view = std::make_shared<InventoryView>();
|
||||
@@ -53,7 +54,7 @@ void InventoryBuilder::addGrid(
|
||||
glm::vec2 pos,
|
||||
int padding,
|
||||
bool addpanel,
|
||||
SlotLayout slotLayout
|
||||
const SlotLayout& slotLayout
|
||||
) {
|
||||
const int slotSize = InventoryView::SLOT_SIZE;
|
||||
const int interval = InventoryView::SLOT_INTERVAL;
|
||||
@@ -95,7 +96,7 @@ void InventoryBuilder::addGrid(
|
||||
}
|
||||
}
|
||||
|
||||
void InventoryBuilder::add(SlotLayout layout) {
|
||||
void InventoryBuilder::add(const SlotLayout& layout) {
|
||||
view->add(view->addSlot(layout), layout.position);
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@ std::shared_ptr<InventoryView> InventoryBuilder::build() {
|
||||
SlotView::SlotView(
|
||||
SlotLayout layout
|
||||
) : UINode(glm::vec2(InventoryView::SLOT_SIZE)),
|
||||
layout(layout)
|
||||
layout(std::move(layout))
|
||||
{
|
||||
setColor(glm::vec4(0, 0, 0, 0.2f));
|
||||
setTooltipDelay(0.05f);
|
||||
@@ -309,7 +310,7 @@ InventoryView::InventoryView() : Container(glm::vec2()) {
|
||||
InventoryView::~InventoryView() {}
|
||||
|
||||
|
||||
std::shared_ptr<SlotView> InventoryView::addSlot(SlotLayout layout) {
|
||||
std::shared_ptr<SlotView> InventoryView::addSlot(const SlotLayout& layout) {
|
||||
uint width = InventoryView::SLOT_SIZE + layout.padding;
|
||||
uint height = InventoryView::SLOT_SIZE + layout.padding;
|
||||
|
||||
@@ -341,7 +342,7 @@ size_t InventoryView::getSlotsCount() const {
|
||||
}
|
||||
|
||||
void InventoryView::bind(
|
||||
std::shared_ptr<Inventory> inventory,
|
||||
const std::shared_ptr<Inventory>& inventory,
|
||||
const Content* content
|
||||
) {
|
||||
this->inventory = inventory;
|
||||
|
||||
Reference in New Issue
Block a user