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
+3 -2
View File
@@ -4,12 +4,13 @@
#include "../../debug/Logger.hpp"
#include <string>
#include <utility>
static debug::Logger logger("al-audio");
using namespace audio;
ALSound::ALSound(ALAudio* al, uint buffer, std::shared_ptr<PCM> pcm, bool keepPCM)
ALSound::ALSound(ALAudio* al, uint buffer, const std::shared_ptr<PCM>& pcm, bool keepPCM)
: al(al), buffer(buffer)
{
duration = pcm->getDuration();
@@ -36,7 +37,7 @@ std::unique_ptr<Speaker> ALSound::newInstance(int priority, int channel) const {
}
ALStream::ALStream(ALAudio* al, std::shared_ptr<PCMStream> source, bool keepSource)
: al(al), source(source), keepSource(keepSource) {
: al(al), source(std::move(source)), keepSource(keepSource) {
}
ALStream::~ALStream() {
+1 -1
View File
@@ -29,7 +29,7 @@ namespace audio {
std::shared_ptr<PCM> pcm;
duration_t duration;
public:
ALSound(ALAudio* al, uint buffer, std::shared_ptr<PCM> pcm, bool keepPCM);
ALSound(ALAudio* al, uint buffer, const std::shared_ptr<PCM>& pcm, bool keepPCM);
~ALSound();
duration_t getDuration() const override {
+1 -1
View File
@@ -2,7 +2,7 @@
using namespace audio;
NoSound::NoSound(std::shared_ptr<PCM> pcm, bool keepPCM) {
NoSound::NoSound(const std::shared_ptr<PCM>& pcm, bool keepPCM) {
duration = pcm->getDuration();
if (keepPCM) {
this->pcm = pcm;
+2 -2
View File
@@ -8,7 +8,7 @@ namespace audio {
std::shared_ptr<PCM> pcm;
duration_t duration;
public:
NoSound(std::shared_ptr<PCM> pcm, bool keepPCM);
NoSound(const std::shared_ptr<PCM>& pcm, bool keepPCM);
~NoSound() {}
duration_t getDuration() const override {
@@ -28,7 +28,7 @@ namespace audio {
std::shared_ptr<PCMStream> source;
duration_t duration;
public:
NoStream(std::shared_ptr<PCMStream> source, bool keepSource) {
NoStream(const std::shared_ptr<PCMStream>& source, bool keepSource) {
duration = source->getTotalDuration();
if (keepSource) {
this->source = source;
+5 -4
View File
@@ -8,6 +8,7 @@
#include <iostream>
#include <stdexcept>
#include <utility>
namespace audio {
static speakerid_t nextId = 1;
@@ -19,7 +20,7 @@ namespace audio {
using namespace audio;
Channel::Channel(std::string name) : name(name) {
Channel::Channel(std::string name) : name(std::move(name)) {
}
float Channel::getVolume() const {
@@ -175,7 +176,7 @@ std::unique_ptr<Sound> audio::load_sound(const fs::path& file, bool keepPCM) {
}
std::unique_ptr<Sound> audio::create_sound(std::shared_ptr<PCM> pcm, bool keepPCM) {
return backend->createSound(pcm, keepPCM);
return backend->createSound(std::move(pcm), keepPCM);
}
std::unique_ptr<PCMStream> audio::open_PCM_stream(const fs::path& file) {
@@ -204,7 +205,7 @@ std::unique_ptr<Stream> audio::open_stream(const fs::path& file, bool keepSource
}
std::unique_ptr<Stream> audio::open_stream(std::shared_ptr<PCMStream> stream, bool keepSource) {
return backend->openStream(stream, keepSource);
return backend->openStream(std::move(stream), keepSource);
}
@@ -276,7 +277,7 @@ speakerid_t audio::play(
}
speakerid_t audio::play(
std::shared_ptr<Stream> stream,
const std::shared_ptr<Stream>& stream,
glm::vec3 position,
bool relative,
float volume,
+1 -1
View File
@@ -437,7 +437,7 @@ namespace audio {
/// @param channel channel index
/// @return speaker id or 0
speakerid_t play(
std::shared_ptr<Stream> stream,
const std::shared_ptr<Stream>& stream,
glm::vec3 position,
bool relative,
float volume,