Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove nested loop from removeDuplicateCuesFromTrack function #1381

Merged
merged 1 commit into from
Mar 20, 2023

Conversation

alex-barstow
Copy link
Contributor

Description

The removeDuplicateCuesFromTrack() function was poorly optimized. The nested loop would run a staggering number of times in cases of very large VTT files. This change accomplishes duplicate cue removal with a single loop.

@codecov
Copy link

codecov bot commented Mar 17, 2023

Codecov Report

Merging #1381 (957d84c) into main (93a2bfd) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1381      +/-   ##
==========================================
- Coverage   85.36%   85.35%   -0.01%     
==========================================
  Files          40       40              
  Lines        9957     9951       -6     
  Branches     2311     2306       -5     
==========================================
- Hits         8500     8494       -6     
  Misses       1457     1457              
Impacted Files Coverage Δ
src/util/text-tracks.js 86.27% <100.00%> (-0.77%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more


if (duplicates.length) {
duplicates.forEach(dupe => track.removeCue(dupe));
for (let i = cues.length - 1; i >= 0; i--) {
Copy link
Contributor Author

@alex-barstow alex-barstow Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

track.removeCue() modifies the track.cues array as we iterate through it, so this iterates backwards to avoid problems from reindexing.

Copy link
Contributor

@adrums86 adrums86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find!

@alex-barstow alex-barstow merged commit 12acbdd into main Mar 20, 2023
@alex-barstow alex-barstow deleted the refactor/remove-duplicate-cue-nested-loop branch March 20, 2023 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants