siku2 / script.service.sponsorblock

Kodi add-on for SponsorBlock
MIT License
124 stars 14 forks source link

fix: remove redundant check #47

Closed SethFalco closed 1 year ago

SethFalco commented 1 year ago

I could be wrong, so please do review and tell me what you think! When I saw this, the first check looked redundant. :thinking:

The first condition can never be true if the one below is false. So, we might as well only check the second condition.

Just to be certain, I ran some number through my head, which I couldn't come up with a scenario where the first condition would match where the second condition wouldn't.

To take it further, I also wrote a script to brute force this and see if the last condition ever occurs:

#!/bin/bash

for combo in {0..10}:{0..10}:{0..10}:{0..10}
do
  IFS=':' read A B C D <<< $combo

  chained_end=$A
  current_time=$B
  reduce_skips_seconds=$C
  seg_start=$D
  min_skip_position=$(( B + C ))

  if [[ $chained_end -lt $current_time ]]
  then
    continue
  fi

  if [[ $seg_start -lt $current_time ]]
  then
    continue
  fi

  if [[ $(( $chained_end - $seg_start )) -lt $reduce_skips_seconds ]]
  then
    continue
  fi

  if [[ $chained_end -lt $min_skip_position ]]
  then
    echo "This isn't possible, is it?"
    exit 0
  fi
done

echo "Nah, never happened."

This prints Nah, never happened..

Notes

Related