Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 63091f8

Browse filesBrowse files
RaisinTenaduh95
authored andcommitted
lib: refactor to use more primordials in internal/histogram.js
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #36455 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent cb7f73c commit 63091f8
Copy full SHA for 63091f8

File tree

Expand file treeCollapse file tree

1 file changed

+12
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+12
-17
lines changed
Open diff view settings
Collapse file

‎lib/internal/histogram.js‎

Copy file name to clipboardExpand all lines: lib/internal/histogram.js
+12-17Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const {
55
} = require('internal/util');
66

77
const { format } = require('util');
8-
const { Map, Symbol } = primordials;
8+
const { SafeMap, Symbol } = primordials;
99

1010
const {
1111
ERR_INVALID_ARG_TYPE,
@@ -19,11 +19,10 @@ const kHandle = Symbol('kHandle');
1919
// record various metrics. This Histogram class provides a
2020
// generally read-only view of the internal histogram.
2121
class Histogram {
22-
#handle = undefined;
23-
#map = new Map();
22+
#map = new SafeMap();
2423

2524
constructor(internal) {
26-
this.#handle = internal;
25+
this[kHandle] = internal;
2726
}
2827

2928
[kInspect]() {
@@ -39,23 +38,23 @@ class Histogram {
3938
}
4039

4140
get min() {
42-
return this.#handle ? this.#handle.min() : undefined;
41+
return this[kHandle]?.min();
4342
}
4443

4544
get max() {
46-
return this.#handle ? this.#handle.max() : undefined;
45+
return this[kHandle]?.max();
4746
}
4847

4948
get mean() {
50-
return this.#handle ? this.#handle.mean() : undefined;
49+
return this[kHandle]?.mean();
5150
}
5251

5352
get exceeds() {
54-
return this.#handle ? this.#handle.exceeds() : undefined;
53+
return this[kHandle]?.exceeds();
5554
}
5655

5756
get stddev() {
58-
return this.#handle ? this.#handle.stddev() : undefined;
57+
return this[kHandle]?.stddev();
5958
}
6059

6160
percentile(percentile) {
@@ -65,26 +64,22 @@ class Histogram {
6564
if (percentile <= 0 || percentile > 100)
6665
throw new ERR_INVALID_ARG_VALUE.RangeError('percentile', percentile);
6766

68-
return this.#handle ? this.#handle.percentile(percentile) : undefined;
67+
return this[kHandle]?.percentile(percentile);
6968
}
7069

7170
get percentiles() {
7271
this.#map.clear();
73-
if (this.#handle)
74-
this.#handle.percentiles(this.#map);
72+
this[kHandle]?.percentiles(this.#map);
7573
return this.#map;
7674
}
7775

7876
reset() {
79-
if (this.#handle)
80-
this.#handle.reset();
77+
this[kHandle]?.reset();
8178
}
8279

8380
[kDestroy]() {
84-
this.#handle = undefined;
81+
this[kHandle] = undefined;
8582
}
86-
87-
get [kHandle]() { return this.#handle; }
8883
}
8984

9085
module.exports = {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.