Skip to content

Commit 9d14f76

Browse files
Cyril Martinbrian-brazil
authored andcommitted
Improve CollectorRegistry#unregister() (#335)
- In 'unregister', remove the collector before its names, so we do instructions in the reverse order compare to 'register'. It is consistent with 'clear'. - So we do 1 lookup in collectors hash map instead of 2. Signed-off-by: Cyril Martin <[email protected]>
1 parent c4ef25c commit 9d14f76

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

simpleclient/src/main/java/io/prometheus/client/CollectorRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public void register(Collector m) {
6666
*/
6767
public void unregister(Collector m) {
6868
synchronized (collectorsToNames) {
69-
for (String name : collectorsToNames.get(m)) {
69+
List<String> names = collectorsToNames.remove(m);
70+
for (String name : names) {
7071
namesToCollectors.remove(name);
7172
}
72-
collectorsToNames.remove(m);
7373
}
7474
}
7575

0 commit comments

Comments
 (0)