-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Use map.putIfAbsent() or map.computeIfAbsent() as appropriate instead of containsKey() + put() #7764
Use map.putIfAbsent() or map.computeIfAbsent() as appropriate instead of containsKey() + put() #7764
Changes from 2 commits
37ebf6e
50b80a0
b8e4473
b54c36e
2b6cf49
a3f6019
0d90c3b
2eb5c81
71a6ce0
0cee976
e3ebf0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,9 +50,7 @@ public Set<DataSegment> findUsedSegments(Set<SegmentIdWithShardSpec> identifiers | |
// Group by dataSource | ||
final Map<String, Set<SegmentIdWithShardSpec>> identifiersByDataSource = new TreeMap<>(); | ||
for (SegmentIdWithShardSpec identifier : identifiers) { | ||
if (!identifiersByDataSource.containsKey(identifier.getDataSource())) { | ||
identifiersByDataSource.put(identifier.getDataSource(), new HashSet<>()); | ||
} | ||
identifiersByDataSource.putIfAbsent(identifier.getDataSource(), new HashSet<>()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good candidate for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
identifiersByDataSource.get(identifier.getDataSource()).add(identifier); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -768,9 +768,7 @@ private Map<Interval, Optional<HyperLogLogCollector>> collectIntervalsAndShardSp | |
} | ||
|
||
if (determineNumPartitions) { | ||
if (!hllCollectors.containsKey(interval)) { | ||
hllCollectors.put(interval, Optional.of(HyperLogLogCollector.makeLatestCollector())); | ||
} | ||
hllCollectors.putIfAbsent(interval, Optional.of(HyperLogLogCollector.makeLatestCollector())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good candidate for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
List<Object> groupKey = Rows.toGroupKey( | ||
queryGranularity.bucketStart(inputRow.getTimestamp()).getMillis(), | ||
|
@@ -781,9 +779,7 @@ private Map<Interval, Optional<HyperLogLogCollector>> collectIntervalsAndShardSp | |
} else { | ||
// we don't need to determine partitions but we still need to determine intervals, so add an Optional.absent() | ||
// for the interval and don't instantiate a HLL collector | ||
if (!hllCollectors.containsKey(interval)) { | ||
hllCollectors.put(interval, Optional.absent()); | ||
} | ||
hllCollectors.putIfAbsent(interval, Optional.absent()); | ||
} | ||
determinePartitionsMeters.incrementProcessed(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,9 +216,7 @@ public Firehose connect(InputRowParser inputRowParser, File temporaryDirectory) | |
for (TimelineObjectHolder<String, DataSegment> holder : timeLineSegments) { | ||
for (PartitionChunk<DataSegment> chunk : holder.getObject()) { | ||
final DataSegment segment = chunk.getObject(); | ||
if (!segmentFileMap.containsKey(segment)) { | ||
segmentFileMap.put(segment, segmentLoader.getSegmentFiles(segment)); | ||
} | ||
segmentFileMap.putIfAbsent(segment, segmentLoader.getSegmentFiles(segment)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
} | ||
|
||
|
@@ -512,9 +510,7 @@ static List<String> getUniqueMetrics(List<TimelineObjectHolder<String, DataSegme | |
for (TimelineObjectHolder<String, DataSegment> timelineHolder : Lists.reverse(timelineSegments)) { | ||
for (PartitionChunk<DataSegment> chunk : timelineHolder.getObject()) { | ||
for (String metric : chunk.getObject().getMetrics()) { | ||
if (!uniqueMetrics.containsKey(metric)) { | ||
uniqueMetrics.put(metric, index++); | ||
} | ||
uniqueMetrics.putIfAbsent(metric, index++); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good candidate for
computeIfAbsent
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.