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
+12 -11
View File
@@ -5,12 +5,13 @@
#include <charconv>
#include <stdexcept>
#include <sstream>
#include <utility>
using namespace xml;
Attribute::Attribute(std::string name, std::string text)
: name(name),
text(text) {
: name(std::move(name)),
text(std::move(text)) {
}
const std::string& Attribute::getName() const {
@@ -104,14 +105,14 @@ glm::vec4 Attribute::asColor() const {
}
}
Node::Node(std::string tag) : tag(tag) {
Node::Node(std::string tag) : tag(std::move(tag)) {
}
void Node::add(xmlelement element) {
void Node::add(const xmlelement& element) {
elements.push_back(element);
}
void Node::set(std::string name, std::string text) {
void Node::set(const std::string& name, const std::string &text) {
attrs[name] = Attribute(name, text);
}
@@ -157,11 +158,11 @@ const xmlelements_map& Node::getAttributes() const {
}
Document::Document(std::string version, std::string encoding)
: version(version),
encoding(encoding) {
: version(std::move(version)),
encoding(std::move(encoding)) {
}
void Document::setRoot(xmlelement element) {
void Document::setRoot(const xmlelement &element) {
this->root = element;
}
@@ -336,7 +337,7 @@ xmldocument Parser::parse() {
return document;
}
xmldocument xml::parse(std::string filename, std::string source) {
xmldocument xml::parse(const std::string& filename, const std::string& source) {
Parser parser(filename, source);
return parser.parse();
}
@@ -357,7 +358,7 @@ inline void newline(
static void stringifyElement(
std::stringstream& ss,
const xmlelement element,
const xmlelement& element,
bool nice,
const std::string& indentStr,
int indent
@@ -414,7 +415,7 @@ static void stringifyElement(
}
std::string xml::stringify(
const xmldocument document,
const xmldocument& document,
bool nice,
const std::string& indentStr
) {