Skip to content

Commit db9cc6f

Browse files
committed
[#noissue] Replace HashSet with Eclipse Collections IntSet to optimize primitive int handling
1 parent 40dbb76 commit db9cc6f

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

web/src/main/java/com/navercorp/pinpoint/web/filter/RpcURLPatternFilter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.navercorp.pinpoint.web.filter;
1818

19-
import com.google.common.collect.ImmutableSet;
2019
import com.navercorp.pinpoint.common.server.bo.AnnotationBo;
2120
import com.navercorp.pinpoint.common.server.bo.SpanBo;
2221
import com.navercorp.pinpoint.common.server.bo.SpanEventBo;
@@ -25,13 +24,14 @@
2524
import com.navercorp.pinpoint.common.util.CollectionUtils;
2625
import com.navercorp.pinpoint.loader.service.AnnotationKeyRegistryService;
2726
import com.navercorp.pinpoint.loader.service.ServiceTypeRegistryService;
27+
import org.eclipse.collections.api.factory.primitive.IntSets;
28+
import org.eclipse.collections.api.set.primitive.IntSet;
29+
import org.eclipse.collections.api.set.primitive.MutableIntSet;
2830
import org.springframework.util.AntPathMatcher;
2931

30-
import java.util.HashSet;
3132
import java.util.List;
3233
import java.util.NoSuchElementException;
3334
import java.util.Objects;
34-
import java.util.Set;
3535

3636
/**
3737
* @author emeroad
@@ -45,7 +45,7 @@ public class RpcURLPatternFilter implements URLPatternFilter {
4545
private final AnnotationKeyRegistryService annotationKeyRegistryService;
4646

4747
// TODO remove. hard coded annotation for compatibility, need a better to group rpc url annotations
48-
private final Set<Integer> rpcEndpointAnnotationCodes;
48+
private final IntSet rpcEndpointAnnotationCodes;
4949

5050
public RpcURLPatternFilter(String urlPattern, ServiceTypeRegistryService serviceTypeRegistryService, AnnotationKeyRegistryService annotationKeyRegistryService) {
5151
this.urlPattern = Objects.requireNonNull(urlPattern, "urlPattern");
@@ -57,12 +57,12 @@ public RpcURLPatternFilter(String urlPattern, ServiceTypeRegistryService service
5757
// TODO remove. hard coded annotation for compatibility, need a better to group rpc url annotations
5858
this.rpcEndpointAnnotationCodes = initRpcEndpointAnnotations(
5959
AnnotationKey.HTTP_URL.getName(), AnnotationKey.MESSAGE_QUEUE_URI.getName(),
60-
"thrift.url", "npc.url", "nimm.url"
60+
"thrift.url", "npc.url"
6161
);
6262
}
6363

64-
private Set<Integer> initRpcEndpointAnnotations(String... annotationKeyNames) {
65-
Set<Integer> rpcEndPointAnnotationCodes = new HashSet<>();
64+
private IntSet initRpcEndpointAnnotations(String... annotationKeyNames) {
65+
MutableIntSet rpcEndPointAnnotationCodes = IntSets.mutable.of();
6666
for (String annotationKeyName : annotationKeyNames) {
6767
try {
6868
final AnnotationKey pluginRpcEndpointAnnotationKey = annotationKeyRegistryService.findAnnotationKeyByName(annotationKeyName);
@@ -73,7 +73,7 @@ private Set<Integer> initRpcEndpointAnnotations(String... annotationKeyNames) {
7373
// ignore
7474
}
7575
}
76-
return ImmutableSet.copyOf(rpcEndPointAnnotationCodes);
76+
return rpcEndPointAnnotationCodes.freeze();
7777
}
7878

7979
@Override

web/src/main/java/com/navercorp/pinpoint/web/mapper/ApplicationNameMapper.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
import com.navercorp.pinpoint.web.vo.Application;
2323
import org.apache.hadoop.hbase.Cell;
2424
import org.apache.hadoop.hbase.client.Result;
25+
import org.eclipse.collections.api.factory.primitive.IntSets;
26+
import org.eclipse.collections.api.set.primitive.MutableIntSet;
2527
import org.springframework.stereotype.Component;
2628

2729
import java.util.ArrayList;
2830
import java.util.Collections;
29-
import java.util.HashSet;
3031
import java.util.List;
3132
import java.util.Objects;
32-
import java.util.Set;
3333

3434
/**
3535
*
@@ -48,19 +48,20 @@ public List<Application> mapRow(Result result, int rowNum) throws Exception {
4848
if (result.isEmpty()) {
4949
return Collections.emptyList();
5050
}
51-
Set<Short> uniqueTypeCodes = new HashSet<>();
51+
MutableIntSet uniqueTypeCodes = IntSets.mutable.of();
5252
String applicationName = CellUtils.rowToString(result);
5353

5454
Cell[] rawCells = result.rawCells();
5555
for (Cell cell : rawCells) {
56-
short serviceTypeCode = CellUtils.valueToShort(cell);
56+
int serviceTypeCode = CellUtils.valueToShort(cell);
5757
uniqueTypeCodes.add(serviceTypeCode);
5858
}
59+
5960
List<Application> applicationList = new ArrayList<>();
60-
for (short serviceTypeCode : uniqueTypeCodes) {
61+
uniqueTypeCodes.forEach(serviceTypeCode -> {
6162
final Application application = applicationFactory.createApplication(applicationName, serviceTypeCode);
6263
applicationList.add(application);
63-
}
64+
});
6465
return applicationList;
6566
}
6667
}

0 commit comments

Comments
 (0)