[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.
This commit is contained in:
parent
2d36945b39
commit
c99d94b615
|
@ -887,12 +887,13 @@ public final class YoutubeParsingHelper {
|
||||||
return textObject.getString("simpleText");
|
return textObject.getString("simpleText");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textObject.getArray("runs").isEmpty()) {
|
final JsonArray runs = textObject.getArray("runs");
|
||||||
|
if (runs.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder textBuilder = new StringBuilder();
|
final StringBuilder textBuilder = new StringBuilder();
|
||||||
for (final Object o : textObject.getArray("runs")) {
|
for (final Object o : runs) {
|
||||||
final JsonObject run = (JsonObject) o;
|
final JsonObject run = (JsonObject) o;
|
||||||
String text = run.getString("text");
|
String text = run.getString("text");
|
||||||
|
|
||||||
|
@ -970,11 +971,12 @@ public final class YoutubeParsingHelper {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textObject.getArray("runs").isEmpty()) {
|
final JsonArray runs = textObject.getArray("runs");
|
||||||
|
if (runs.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Object textPart : textObject.getArray("runs")) {
|
for (final Object textPart : runs) {
|
||||||
final String url = getUrlFromNavigationEndpoint(((JsonObject) textPart)
|
final String url = getUrlFromNavigationEndpoint(((JsonObject) textPart)
|
||||||
.getObject("navigationEndpoint"));
|
.getObject("navigationEndpoint"));
|
||||||
if (!isNullOrEmpty(url)) {
|
if (!isNullOrEmpty(url)) {
|
||||||
|
|
Loading…
Reference in New Issue