Skip to content

Commit

Permalink
move cache to WeakMap
Browse files Browse the repository at this point in the history
  • Loading branch information
ngavalas committed Mar 12, 2023
1 parent f1f2dfd commit dcb5c3f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,16 @@ function formatLabels(labels) {
);
}

const sharedLabelCache = new WeakMap();
function flattenSharedLabels(labels) {
if (labels.__flattened_internal) {
return labels.__flattened_internal;
const cached = sharedLabelCache.get(labels);
if (cached) {
return cached;
}

const formattedLabels = formatLabels(labels);
const flattened = formattedLabels.join(',');
Object.defineProperty(labels, '__flattened_internal', { value: flattened });
sharedLabelCache.set(labels, flattened);
return flattened;
}
function escapeLabelValue(str) {
Expand Down

0 comments on commit dcb5c3f

Please # to comment.