summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibAudio
diff options
context:
space:
mode:
authorkleines Filmröllchen <malu.bertsch@gmail.com>2021-10-03 19:01:44 +0200
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-11-28 13:33:51 -0800
commit8608cd11e4600d3dc3bac093e2a863be9a721597 (patch)
treee5b99aa9f91e769fb118fb2528abe32ed241a3a1 /Userland/Libraries/LibAudio
parent295eec2d49b0c361a99915cbcabf33a0a296df32 (diff)
downloadserenity-8608cd11e4600d3dc3bac093e2a863be9a721597.zip
LibAudio: Optimize sample moves in FlacLoader
As long as possible, entire decoded frame sample vectors are moved into the output vector, leading to up to 20% speedups by avoiding memmoves on take_first.
Diffstat (limited to 'Userland/Libraries/LibAudio')
-rw-r--r--Userland/Libraries/LibAudio/FlacLoader.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/Userland/Libraries/LibAudio/FlacLoader.cpp b/Userland/Libraries/LibAudio/FlacLoader.cpp
index d0d40d9ff4..ff3774d04b 100644
--- a/Userland/Libraries/LibAudio/FlacLoader.cpp
+++ b/Userland/Libraries/LibAudio/FlacLoader.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include "AK/StdLibExtras.h"
#include <AK/Debug.h>
#include <AK/FlyString.h>
#include <AK/Format.h>
@@ -199,15 +200,25 @@ LoaderSamples FlacLoaderPlugin::get_more_samples(size_t max_bytes_to_read_from_i
return Buffer::create_empty();
size_t samples_to_read = min(max_bytes_to_read_from_input, remaining_samples);
+ samples.ensure_capacity(samples_to_read);
while (samples_to_read > 0) {
if (!m_current_frame.has_value())
TRY(next_frame());
- samples.append(m_current_frame_data.take_first());
- if (m_current_frame_data.is_empty()) {
+ // Do a full vector extend if possible
+ if (m_current_frame_data.size() <= samples_to_read) {
+ samples_to_read -= m_current_frame_data.size();
+ samples.extend(move(m_current_frame_data));
+ m_current_frame_data.clear();
m_current_frame.clear();
+ } else {
+ samples.unchecked_append(m_current_frame_data.data(), samples_to_read);
+ m_current_frame_data.remove(0, samples_to_read);
+ if (m_current_frame_data.size() == 0) {
+ m_current_frame.clear();
+ }
+ samples_to_read = 0;
}
- --samples_to_read;
}
m_loaded_samples += samples.size();