mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-14 01:04:38 +03:00
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.
This commit is contained in:
parent
295eec2d49
commit
8608cd11e4
Notes:
sideshowbarker
2024-07-18 00:33:48 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/8608cd11e46 Pull-request: https://github.com/SerenityOS/serenity/pull/10331 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/alimpfard
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user