Optimize parameter passing to avoid unnecessary copying
This commit is contained in:
@@ -42,7 +42,7 @@ ImageData* Atlas::getImage() const {
|
||||
return image.get();
|
||||
}
|
||||
|
||||
void AtlasBuilder::add(std::string name, std::unique_ptr<ImageData> image) {
|
||||
void AtlasBuilder::add(const std::string& name, std::unique_ptr<ImageData> image) {
|
||||
entries.push_back(atlasentry{name, std::shared_ptr<ImageData>(image.release())});
|
||||
names.insert(name);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class AtlasBuilder {
|
||||
std::set<std::string> names;
|
||||
public:
|
||||
AtlasBuilder() {}
|
||||
void add(std::string name, std::unique_ptr<ImageData> image);
|
||||
void add(const std::string& name, std::unique_ptr<ImageData> image);
|
||||
bool has(const std::string& name) const;
|
||||
const std::set<std::string>& getNames() { return names; };
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "Batch2D.hpp"
|
||||
#include "Framebuffer.hpp"
|
||||
#include "../../window/Window.hpp"
|
||||
@@ -23,10 +25,10 @@ static void set_blend_mode(BlendMode mode) {
|
||||
|
||||
DrawContext::DrawContext(
|
||||
const DrawContext* parent,
|
||||
const Viewport& viewport,
|
||||
Viewport viewport,
|
||||
Batch2D* g2d
|
||||
) : parent(parent),
|
||||
viewport(viewport),
|
||||
viewport(std::move(viewport)),
|
||||
g2d(g2d)
|
||||
{}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class DrawContext {
|
||||
BlendMode blendMode = BlendMode::normal;
|
||||
int scissorsCount = 0;
|
||||
public:
|
||||
DrawContext(const DrawContext* parent, const Viewport& viewport, Batch2D* g2d);
|
||||
DrawContext(const DrawContext* parent, Viewport viewport, Batch2D* g2d);
|
||||
~DrawContext();
|
||||
|
||||
Batch2D* getBatch2D() const;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#include "Font.hpp"
|
||||
|
||||
#include <utility>
|
||||
#include "Texture.hpp"
|
||||
#include "Batch2D.hpp"
|
||||
|
||||
@@ -43,7 +45,7 @@ int Font::calcWidth(const std::wstring& text, size_t offset, size_t length) {
|
||||
}
|
||||
|
||||
void Font::draw(Batch2D* batch, std::wstring text, int x, int y) {
|
||||
draw(batch, text, x, y, FontStyle::none);
|
||||
draw(batch, std::move(text), x, y, FontStyle::none);
|
||||
}
|
||||
|
||||
static inline void drawGlyph(Batch2D* batch, int x, int y, uint c, FontStyle style) {
|
||||
@@ -66,7 +68,7 @@ static inline void drawGlyph(Batch2D* batch, int x, int y, uint c, FontStyle sty
|
||||
batch->sprite(x, y, GLYPH_SIZE, GLYPH_SIZE, 16, c, batch->getColor());
|
||||
}
|
||||
|
||||
void Font::draw(Batch2D* batch, std::wstring text, int x, int y, FontStyle style) {
|
||||
void Font::draw(Batch2D* batch, const std::wstring& text, int x, int y, FontStyle style) {
|
||||
draw(batch, std::wstring_view(text.c_str(), text.length()), x, y, style);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
/// @param codepoint character unicode codepoint
|
||||
bool isPrintableChar(uint codepoint) const;
|
||||
void draw(Batch2D* batch, std::wstring text, int x, int y);
|
||||
void draw(Batch2D* batch, std::wstring text, int x, int y, FontStyle style);
|
||||
void draw(Batch2D* batch, const std::wstring& text, int x, int y, FontStyle style);
|
||||
void draw(Batch2D* batch, std::wstring_view text, int x, int y, FontStyle style);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user