Skip to content

Commit

Permalink
Replace map with set. (netty#9833)
Browse files Browse the repository at this point in the history
Motivation:
Replace Map with Set. `reportedLeaks` has better semantics as a Set, and if it is a Map, it seems that the value of this Map has no meaning to us.

Modifications:

Use Set.

Result:
Cleaner code
  • Loading branch information
carryxyh authored and normanmaurer committed Dec 4, 2019
1 parent 9ba13f0 commit df121e5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions common/src/main/java/io/netty/util/ResourceLeakDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ public static Level getLevel() {
Collections.newSetFromMap(new ConcurrentHashMap<DefaultResourceLeak<?>, Boolean>());

private final ReferenceQueue<Object> refQueue = new ReferenceQueue<Object>();
private final ConcurrentMap<String, Boolean> reportedLeaks = PlatformDependent.newConcurrentHashMap();
private final Set<String> reportedLeaks =
Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());

private final String resourceType;
private final int samplingInterval;
Expand Down Expand Up @@ -271,7 +272,6 @@ private DefaultResourceLeak track0(T obj) {

private void clearRefQueue() {
for (;;) {
@SuppressWarnings("unchecked")
DefaultResourceLeak ref = (DefaultResourceLeak) refQueue.poll();
if (ref == null) {
break;
Expand All @@ -288,7 +288,6 @@ private void reportLeak() {

// Detect and report previous leaks.
for (;;) {
@SuppressWarnings("unchecked")
DefaultResourceLeak ref = (DefaultResourceLeak) refQueue.poll();
if (ref == null) {
break;
Expand All @@ -299,7 +298,7 @@ private void reportLeak() {
}

String records = ref.toString();
if (reportedLeaks.putIfAbsent(records, Boolean.TRUE) == null) {
if (reportedLeaks.add(records)) {
if (records.isEmpty()) {
reportUntracedLeak(resourceType);
} else {
Expand Down

0 comments on commit df121e5

Please sign in to comment.