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

Make improvements to methods using toArray(). #886

Merged
merged 1 commit into from
Aug 6, 2022

Conversation

Isira-Seneviratne
Copy link
Member

Comment on lines 84 to 85
final String[] keySet = kioskList.keySet().toArray(new String[0]);
return getExtractorById(keySet[0], nextPage, localization);
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be improved, in order to avoid uselessly converting the list to an array (my code was not checked, improve it if there are warnings)

Suggested change
final String[] keySet = kioskList.keySet().toArray(new String[0]);
return getExtractorById(keySet[0], nextPage, localization);
final String kioskId = kioskList.keySet().stream().findAny().get();
return getExtractorById(kioskId, nextPage, localization);

@@ -124,9 +125,7 @@ public static String[] getLinksFromString(final String txt) throws ParsingExcept
links.add(txt.substring(ls.getBeginIndex(), ls.getEndIndex()));
}

String[] linksarray = new String[links.size()];
linksarray = links.toArray(linksarray);
return linksarray;
Copy link
Member

Choose a reason for hiding this comment

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

I think this method is just unused... Should we remove it or keep it in case it becomes handy later? In the second case, just change the function signature and avoid converting links to an array

@Isira-Seneviratne Isira-Seneviratne changed the title Use toArray() with zero-length arrays. Make improvements to methods using toArray(). Aug 5, 2022
Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

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

LGTM

@Stypox Stypox merged commit d120036 into TeamNewPipe:dev Aug 6, 2022
@Isira-Seneviratne Isira-Seneviratne deleted the toArray_improvements branch August 9, 2022 02:44
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.

2 participants