fix container inefficiency in RSSExpandedReader.java (#1782)

This commit is contained in:
cinsttool 2024-04-02 20:14:21 +08:00 committed by GitHub
parent c77778ee03
commit accc4d5ead
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -222,25 +222,24 @@ public final class RSSExpandedReader extends AbstractRSSReader {
private List<ExpandedPair> checkRows(List<ExpandedRow> collectedRows, int currentRow) throws NotFoundException { private List<ExpandedPair> checkRows(List<ExpandedRow> collectedRows, int currentRow) throws NotFoundException {
for (int i = currentRow; i < rows.size(); i++) { for (int i = currentRow; i < rows.size(); i++) {
ExpandedRow row = rows.get(i); ExpandedRow row = rows.get(i);
this.pairs.clear();
for (ExpandedRow collectedRow : collectedRows) {
this.pairs.addAll(collectedRow.getPairs());
}
this.pairs.addAll(row.getPairs()); this.pairs.addAll(row.getPairs());
int addSize = row.getPairs().size();
if (isValidSequence(this.pairs, false)) { if (isValidSequence(this.pairs, false)) {
if (checkChecksum()) { if (checkChecksum()) {
return this.pairs; return this.pairs;
} }
collectedRows.add(row);
List<ExpandedRow> rs = new ArrayList<>(collectedRows);
rs.add(row);
try { try {
// Recursion: try to add more rows // Recursion: try to add more rows
return checkRows(rs, i + 1); return checkRows(collectedRows, i + 1);
} catch (NotFoundException e) { } catch (NotFoundException e) {
// We failed, try the next candidate // We failed, try the next candidate
collectedRows.remove(collectedRows.size() - 1);
this.pairs.subList(this.pairs.size() - addSize, this.pairs.size()).clear();
} }
} else {
this.pairs.subList(this.pairs.size() - addSize, this.pairs.size()).clear();
} }
} }