Skip to content

Commit

Permalink
refactor: faster erase
Browse files Browse the repository at this point in the history
  • Loading branch information
Neko-Life committed Apr 13, 2024
1 parent c808c67 commit a8e4c00
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/dpp/discordvoiceclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,20 +1167,29 @@ uint32_t discord_voice_client::get_tracks_remaining() {

discord_voice_client& discord_voice_client::skip_to_next_marker() {
std::lock_guard<std::mutex> lock(this->stream_mutex);
/* Keep popping the first entry off the outbuf until the first entry is a track marker */
while (!outbuf.empty() && outbuf[0].packet.size() != sizeof(uint16_t) && (*((uint16_t*)(outbuf[0].packet.data()))) != AUDIO_TRACK_MARKER) {
outbuf.erase(outbuf.begin());
}
if (outbuf.size()) {
/* Remove the actual track marker out of the buffer */
outbuf.erase(outbuf.begin());
if (!outbuf.empty()) {
/* Find the first marker to skip to */
auto i = std::find_if(outbuf.begin(), outbuf.end(), [](const voice_out_packet &v){
return v.packet.size() == sizeof(uint16_t) && (*((uint16_t*)(v.packet.data()))) == AUDIO_TRACK_MARKER;

Check notice on line 1173 in src/dpp/discordvoiceclient.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/dpp/discordvoiceclient.cpp#L1173

C-style pointer casting
});

if (i != outbuf.end()) {
/* Skip queued packets until including found marker */
outbuf.erase(outbuf.begin(), i);
} else {
/* No market found, skip the whole queue */
outbuf.clear();
}
}

if (tracks > 0) {
tracks--;
}

if (!track_meta.empty()) {
track_meta.erase(track_meta.begin());
}

return *this;
}

Expand Down

0 comments on commit a8e4c00

Please sign in to comment.