apache / apache/dubbo

code optimization

Open
#10,816 0 comments 1 reaction 0 assignees View on GitHub
type/discussion
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

```
// org.apache.dubbo.common.utils.CollectionUtils#269
public static Set ofSet(T... values) {
int size = values == null ? 0 : values.length;
if (size < 1) {
return emptySet();
}

float loadFactor = 1f / ((size + 1) * 1.0f);

if (loadFactor > 0.75f) {
loadFactor = 0.75f;
}

Set elements = new LinkedHashSet<>(size, loadFactor);
for (int i = 0; i < size; i++) {
elements.add(values[i]);
}
return unmodifiableSet(elements);
}
```
in this code, loadFactor is never large than o.75f and too small can lead to frequent rehash, so set loadFactor o.75f is ok?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.