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

Minor memory optimizations (#1960) #1962

Merged
merged 7 commits into from
Nov 2, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -498,7 +498,7 @@ private void parseChromeSearches(ContentHandler handler, Metadata metadata, Pars

protected List<ResumedVisit> getResumedHistory(Connection connection, Metadata metadata, ParseContext context)
throws SQLException {
List<ResumedVisit> resumedHistory = new LinkedList<ResumedVisit>();
List<ResumedVisit> resumedHistory = new ArrayList<ResumedVisit>();

Statement st = null;
try {
Expand All @@ -524,7 +524,7 @@ protected List<ResumedVisit> getResumedHistory(Connection connection, Metadata m

protected List<Visit> getHistory(Connection connection, Metadata metadata, ParseContext context)
throws SQLException {
List<Visit> history = new LinkedList<Visit>();
List<Visit> history = new ArrayList<Visit>();

Statement st = null;
try {
Expand All @@ -549,7 +549,7 @@ protected List<Visit> getHistory(Connection connection, Metadata metadata, Parse

protected List<Download> getDownloads(Connection connection, Metadata metadata, ParseContext context)
throws SQLException {
List<Download> downloads = new LinkedList<Download>();
List<Download> downloads = new ArrayList<Download>();

Statement st = null;
try {
Expand Down Expand Up @@ -582,7 +582,7 @@ protected List<Download> getDownloads(Connection connection, Metadata metadata,

protected List<Search> getSearchTerms(Connection connection, Metadata metadata, ParseContext context)
throws SQLException {
List<Search> searches = new LinkedList<Search>();
List<Search> searches = new ArrayList<Search>();

Statement st = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -287,7 +287,7 @@ private void parseEdgeHistory(ContentHandler handler, Metadata metadata, ParseCo

protected List<EdgeContainer> getHistory(String filePath, PointerByReference filePointerReference, ItemInfo itemInfo)
throws EdgeWebCacheException {
List<EdgeContainer> history = new LinkedList<EdgeContainer>();
List<EdgeContainer> history = new ArrayList<EdgeContainer>();

try {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -504,7 +504,7 @@ private void parseFirefoxResumedHistory(ContentHandler handler, Metadata metadat

protected List<ResumedVisit> getResumedHistory(Connection connection, Metadata metadata, ParseContext context)
throws SQLException {
List<ResumedVisit> resumedHistory = new LinkedList<ResumedVisit>();
List<ResumedVisit> resumedHistory = new ArrayList<ResumedVisit>();

Statement st = null;
try {
Expand All @@ -531,7 +531,7 @@ protected List<ResumedVisit> getResumedHistory(Connection connection, Metadata m

protected List<Visit> getHistory(Connection connection, Metadata metadata, ParseContext context)
throws SQLException {
List<Visit> history = new LinkedList<Visit>();
List<Visit> history = new ArrayList<Visit>();

Statement st = null;
try {
Expand All @@ -555,7 +555,7 @@ protected List<Visit> getHistory(Connection connection, Metadata metadata, Parse

protected List<FirefoxMozBookmark> getBookmarks(Connection connection, Metadata metadata, ParseContext context)
throws SQLException {
List<FirefoxMozBookmark> bookmarks = new LinkedList<FirefoxMozBookmark>();
List<FirefoxMozBookmark> bookmarks = new ArrayList<FirefoxMozBookmark>();

Statement st = null;
try {
Expand All @@ -580,7 +580,7 @@ protected List<FirefoxMozBookmark> getBookmarks(Connection connection, Metadata

private List<Download> getDownloads(Connection connection, Metadata metadata, ParseContext context)
throws SQLException, JsonParseException, JsonMappingException, IOException {
List<Download> downloads = new LinkedList<Download>();
List<Download> downloads = new ArrayList<Download>();

Statement st = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -342,7 +342,7 @@ private void parseSafariResumedHistory(InputStream stream, ContentHandler handle
}

protected List<SafariResumedVisit> getResumedHistory(InputStream is) throws Exception {
List<SafariResumedVisit> resumedHistory = new LinkedList<SafariResumedVisit>();
List<SafariResumedVisit> resumedHistory = new ArrayList<SafariResumedVisit>();

NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(is);
NSObject[] parameters = ((NSArray) rootDict.objectForKey("WebHistoryDates")).getArray();
Expand Down Expand Up @@ -371,7 +371,7 @@ protected List<SafariResumedVisit> getResumedHistory(InputStream is) throws Exce
}

// protected List<SafariVisit> getHistory(InputStream is) throws Exception {
// List<SafariVisit> history = new LinkedList<SafariVisit>();
// List<SafariVisit> history = new ArrayList<SafariVisit>();
//
// NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(is);
// NSObject[] parameters = ((NSArray)
Expand Down Expand Up @@ -400,7 +400,7 @@ protected List<SafariResumedVisit> getResumedHistory(InputStream is) throws Exce
// }

private List<Download> getDownloads(InputStream is) throws Exception {
List<Download> downloads = new LinkedList<>();
List<Download> downloads = new ArrayList<>();

NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(is);
NSObject[] parameters = ((NSArray) rootDict.objectForKey("DownloadHistory")).getArray();
Expand Down Expand Up @@ -555,7 +555,7 @@ private void parseChildren(List<SafariBookmark> bookmarks, NSDictionary dict) {
}

private List<SafariBookmark> getBookmarks(InputStream is) throws Exception {
List<SafariBookmark> bookmarks = new LinkedList<SafariBookmark>();
List<SafariBookmark> bookmarks = new ArrayList<SafariBookmark>();

NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(is);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -229,7 +229,7 @@ private void parseSafariResumedHistory(ContentHandler handler, Metadata metadata

protected List<SafariResumedVisit> getResumedHistory(Connection connection, Metadata metadata, ParseContext context)
throws SQLException {
List<SafariResumedVisit> resumedHistory = new LinkedList<SafariResumedVisit>();
List<SafariResumedVisit> resumedHistory = new ArrayList<SafariResumedVisit>();

Statement st = null;
try {
Expand Down Expand Up @@ -273,7 +273,7 @@ protected List<SafariResumedVisit> getResumedHistory(Connection connection, Meta

protected List<SafariVisit> getHistory(Connection connection, Metadata metadata, ParseContext context)
throws SQLException {
List<SafariVisit> history = new LinkedList<SafariVisit>();
List<SafariVisit> history = new ArrayList<SafariVisit>();

Statement st = null;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package iped.parsers.discord.json;

import java.util.HashSet;
import java.util.Set;
import java.util.Collections;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down Expand Up @@ -42,7 +42,7 @@ public class DiscordAttachment {

private String mediaHash;

private Set<String> childPornSets = new HashSet<>();
private List<String> childPornSets;

public String getId() {
return id;
Expand Down Expand Up @@ -122,15 +122,11 @@ public String getMediaHash() {

public void setMediaHash(String mediaHash) {
this.mediaHash = mediaHash;
childPornSets.addAll(ChildPornHashLookup.lookupHash(mediaHash));
childPornSets = ChildPornHashLookup.lookupHashAndMerge(mediaHash, childPornSets);
}

public Set<String> getChildPornSets() {
return childPornSets;
}

public void setChildPornSets(Set<String> childPornSets) {
this.childPornSets = childPornSets;
public List<String> getChildPornSets() {
return childPornSets == null ? Collections.emptyList() : childPornSets;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;
Expand Down Expand Up @@ -199,13 +198,12 @@ public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
cells.add(e.getName());
String hash = e.getHash();
metadata.add(ExtraProperties.SHARED_HASHES, hash);
HashSet<String> hashSets = new HashSet<>();
hashSets.addAll(ChildPornHashLookup.lookupHash(EDONKEY, hash));
List<String> hashSets = ChildPornHashLookup.lookupHash(EDONKEY, hash);
item = searchItemInCase(searcher, EDONKEY, e.getHash());
if(item != null) {
hashSets.addAll(ChildPornHashLookup.lookupHash(item.getHash()));
hashSets = ChildPornHashLookup.lookupHashAndMerge(EDONKEY, hash, hashSets);
}
if (!hashSets.isEmpty()) {
if (hashSets != null && !hashSets.isEmpty()) {
hashDBHits++;
trClass = "rr"; //$NON-NLS-1$
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TimeZone;

Expand Down Expand Up @@ -115,12 +115,11 @@ public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
xhtml.startElement("table", "class", "d");

int hashDBHits = 0;
HashSet<String> hashSets = new HashSet<String>();
hashSets.addAll(ChildPornHashLookup.lookupHash(KnownMetParser.EDONKEY, e.getHash()));
List<String> hashSets = ChildPornHashLookup.lookupHash(KnownMetParser.EDONKEY, e.getHash());
IItemReader item = KnownMetParser.searchItemInCase(searcher, KnownMetParser.EDONKEY, e.getHash());
if (item != null)
hashSets.addAll(ChildPornHashLookup.lookupHash(item.getHash()));
if (!hashSets.isEmpty())
hashSets = ChildPornHashLookup.lookupHashAndMerge(item.getHash(), hashSets);
if (hashSets != null && !hashSets.isEmpty())
hashDBHits++;

AttributesImpl attributes = new AttributesImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;

import javax.swing.text.html.HTMLEditorKit.Parser;
Expand Down Expand Up @@ -159,7 +159,7 @@ public String handleCell(ResultSet results, ResultSetMetaData rsmd, int i, Conte
}

public List<String> getHeaders() throws IOException {
List<String> headers = new LinkedList<String>();
List<String> headers = new ArrayList<String>();
// lazy initialization
if (results == null) {
results = getTableData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -65,7 +65,7 @@ public class LibraryFile extends ShareazaEntity {
private boolean cachedPreview;
private boolean bogus;
private final LibraryFolder parentFolder;
private HashSet<String> hashSetHits = new HashSet<>();
private List<String> hashSetHits;

public LibraryFile(LibraryFolder parentFolder) {
super("LIBRARY FILE"); //$NON-NLS-1$
Expand Down Expand Up @@ -208,14 +208,14 @@ public boolean isShared() {

public void printTableRow(XHTMLContentHandler html, String path, IItemSearcher searcher, Map<Integer, List<String>> albunsForFiles) throws SAXException {

hashSetHits.addAll(ChildPornHashLookup.lookupHash(md5));
hashSetHits.addAll(ChildPornHashLookup.lookupHash(sha1));
hashSetHits = ChildPornHashLookup.lookupHashAndMerge(md5, hashSetHits);
hashSetHits = ChildPornHashLookup.lookupHashAndMerge(sha1, hashSetHits);

AttributesImpl attributes = new AttributesImpl();
if (md5 != null && !md5.isEmpty()) {
attributes.addAttribute("", "name", "name", "CDATA", md5.toUpperCase());
}
if (!hashSetHits.isEmpty()) {
if (hashSetHits != null && !hashSetHits.isEmpty()) {
attributes.addAttribute("", "class", "class", "CDATA", "r");
}
html.startElement("tr", attributes);
Expand Down Expand Up @@ -260,7 +260,7 @@ private void printTd(XHTMLContentHandler html, IItemSearcher searcher, Object...
col++;
}
html.startElement("td"); //$NON-NLS-1$
if (!hashSetHits.isEmpty()) {
if (hashSetHits != null && !hashSetHits.isEmpty()) {
html.characters(hashSetHits.toString());
}
html.endElement("td"); //$NON-NLS-1$
Expand All @@ -270,7 +270,7 @@ private void printTd(XHTMLContentHandler html, IItemSearcher searcher, Object...
}

public boolean isHashDBHit() {
return !hashSetHits.isEmpty();
return hashSetHits != null && !hashSetHits.isEmpty();
}

public long getSize() {
Expand Down Expand Up @@ -377,8 +377,8 @@ public LibraryFolder getParentFolder() {
return parentFolder;
}

public HashSet<String> getHashSetHits() {
return hashSetHits;
public List<String> getHashSetHits() {
return hashSetHits == null ? Collections.emptyList() : hashSetHits;
}

public void setIndex(int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -189,7 +189,7 @@ protected String getJDBCClassName() {
@Override
protected List<String> getTableNames(Connection connection, Metadata metadata, ParseContext context)
throws SQLException {
List<String> tableNames = new LinkedList<String>();
List<String> tableNames = new ArrayList<String>();

Statement st = null;
try {
Expand Down
Loading
Loading