Skip to content

Commit c99d94b

Browse files
committed
[YouTube] Do not get twice runs array in YoutubeParsingHelper
The runs object was computed twice in getTextFromObject and getUrlFromObject methods, leading to unneeded search costs. This has been avoided by storing the array in method variables.
1 parent 2d36945 commit c99d94b

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,12 +887,13 @@ public static String getTextFromObject(final JsonObject textObject, final boolea
887887
return textObject.getString("simpleText");
888888
}
889889

890-
if (textObject.getArray("runs").isEmpty()) {
890+
final JsonArray runs = textObject.getArray("runs");
891+
if (runs.isEmpty()) {
891892
return null;
892893
}
893894

894895
final StringBuilder textBuilder = new StringBuilder();
895-
for (final Object o : textObject.getArray("runs")) {
896+
for (final Object o : runs) {
896897
final JsonObject run = (JsonObject) o;
897898
String text = run.getString("text");
898899

@@ -970,11 +971,12 @@ public static String getUrlFromObject(final JsonObject textObject) {
970971
return null;
971972
}
972973

973-
if (textObject.getArray("runs").isEmpty()) {
974+
final JsonArray runs = textObject.getArray("runs");
975+
if (runs.isEmpty()) {
974976
return null;
975977
}
976978

977-
for (final Object textPart : textObject.getArray("runs")) {
979+
for (final Object textPart : runs) {
978980
final String url = getUrlFromNavigationEndpoint(((JsonObject) textPart)
979981
.getObject("navigationEndpoint"));
980982
if (!isNullOrEmpty(url)) {

0 commit comments

Comments
 (0)