[tor-commits] [collector/release] Avoid manual array copies.
karsten at torproject.org
karsten at torproject.org
Mon Oct 15 14:39:13 UTC 2018
commit 82444f7e3f8e03a039aa6a33e3db9a4ac1a8da24
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date: Mon Aug 20 15:42:34 2018 +0200
Avoid manual array copies.
---
.../metrics/collector/bridgedescs/BridgeSnapshotReader.java | 5 ++---
.../torproject/metrics/collector/exitlists/ExitListDownloader.java | 4 +---
.../org/torproject/metrics/collector/relaydescs/ArchiveReader.java | 5 ++---
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeSnapshotReader.java b/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeSnapshotReader.java
index 85c593d..0ffb233 100644
--- a/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeSnapshotReader.java
+++ b/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeSnapshotReader.java
@@ -22,6 +22,7 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
@@ -82,9 +83,7 @@ public class BridgeSnapshotReader {
while (!filesInInputDir.isEmpty()) {
File pop = filesInInputDir.pop();
if (pop.isDirectory()) {
- for (File f : pop.listFiles()) {
- filesInInputDir.add(f);
- }
+ Collections.addAll(filesInInputDir, pop.listFiles());
} else if (!parsed.contains(pop.getName())) {
try {
FileInputStream in = new FileInputStream(pop);
diff --git a/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java b/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java
index 2531cb7..4f9d082 100644
--- a/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java
+++ b/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java
@@ -174,9 +174,7 @@ public class ExitListDownloader extends CollecTorMain {
while (lastThreeElements.size() > 3) {
lastThreeElements.remove(lastThreeElements.first());
}
- for (File f : lastThreeElements) {
- filesInInputDir.add(f);
- }
+ filesInInputDir.addAll(lastThreeElements);
} else {
lastThreeExitLists.add(pop);
while (lastThreeExitLists.size() > 3) {
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
index 0119aef..72960b0 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
@@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -86,9 +87,7 @@ public class ArchiveReader {
while (!filesInInputDir.isEmpty()) {
File pop = filesInInputDir.pop();
if (pop.isDirectory()) {
- for (File f : pop.listFiles()) {
- filesInInputDir.add(f);
- }
+ Collections.addAll(filesInInputDir, pop.listFiles());
} else {
try {
BufferedInputStream bis = null;
More information about the tor-commits
mailing list