From 3504912eba0f7943a712df62e401d0e1caaa7a9e Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Thu, 22 Sep 2022 08:38:49 +0200 Subject: [PATCH] fix(custom-playback-speed): implement own method instead of `takeWhile` --- .../patch/CustomPlaybackSpeedPatch.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/customplaybackspeed/patch/CustomPlaybackSpeedPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/customplaybackspeed/patch/CustomPlaybackSpeedPatch.kt index 75ec992aa..ac88801f8 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/customplaybackspeed/patch/CustomPlaybackSpeedPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/customplaybackspeed/patch/CustomPlaybackSpeedPatch.kt @@ -88,7 +88,7 @@ class CustomPlaybackSpeedPatch : BytecodePatch( "sget-object v$originalArrayFetchDestination, $videoSpeedsArrayType" ) - val limiterMethod = SpeedLimiterFingerprint.result?.mutableMethod!!; + val limiterMethod = SpeedLimiterFingerprint.result?.mutableMethod!! val limiterMethodImpl = limiterMethod.implementation!! val (limiterMinConstIndex, limiterMinConst) = limiterMethodImpl.instructions.withIndex() @@ -123,11 +123,16 @@ class CustomPlaybackSpeedPatch : BytecodePatch( .div(stepsGranularity)// round to nearest multiple of stepsGranularity .coerceAtLeast(1 / stepsGranularity) // ensure steps are at least 1/8th of the step granularity - val videoSpeedsArray = DoubleStream - .iterate(speedLimitMin.toDouble()) { it + step } // create a stream of speeds - .takeWhile { it <= speedLimitMax } // limit the stream to the max speed - .mapToObj { it.toFloat().toRawBits() } - .toList() as List + val videoSpeedsArray = buildList { + DoubleStream + .iterate(speedLimitMin.toDouble()) { it + step } // create a stream of speeds + .let { speedStream -> + for (speed in speedStream) { + if (speed > speedLimitMax) break + add(speed.toFloat().toRawBits()) + } + } + } // adjust the new array of speeds size constructor.replaceInstruction(