Skip to content

Commit 63091f8

Browse files
RaisinTenaduh95
authored andcommitted
lib: refactor to use more primordials in internal/histogram.js
Co-authored-by: Antoine du Hamel <[email protected]> PR-URL: #36455 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent cb7f73c commit 63091f8

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

‎lib/internal/histogram.js‎

Lines 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
classHistogram{
22-
#handle =undefined;
23-
#map =newMap();
22+
#map =newSafeMap();
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
getmin(){
42-
returnthis.#handle ? this.#handle.min() : undefined;
41+
returnthis[kHandle]?.min();
4342
}
4443

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

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

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

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

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

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

7170
getpercentiles(){
7271
this.#map.clear();
73-
if(this.#handle)
74-
this.#handle.percentiles(this.#map);
72+
this[kHandle]?.percentiles(this.#map);
7573
returnthis.#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](){returnthis.#handle;}
8883
}
8984

9085
module.exports={

0 commit comments

Comments
(0)