@@ -21,7 +21,7 @@ export interface Styles {
21
21
/**
22
22
* Quick dictionary lookup for unit-less numbers.
23
23
*/
24
- const CSS_NUMBER = Object . create ( null ) as Record < string , true > ;
24
+ const CSS_NUMBER = new Set < string > ( ) ;
25
25
26
26
/**
27
27
* CSS properties that are valid unit-less numbers.
@@ -79,7 +79,7 @@ const CSS_NUMBER_KEYS = [
79
79
// Add vendor prefixes to all unit-less properties.
80
80
for ( const property of CSS_NUMBER_KEYS ) {
81
81
for ( const prefix of [ "-webkit-" , "-ms-" , "-moz-" , "-o-" , "" ] ) {
82
- CSS_NUMBER [ prefix + property ] = true ;
82
+ CSS_NUMBER . add ( prefix + property ) ;
83
83
}
84
84
}
85
85
@@ -156,7 +156,7 @@ type Tuple<T> = [string, T];
156
156
* Transform a style string to a CSS string.
157
157
*/
158
158
function tupleToStyle ( [ name , value ] : Tuple < NonNullable < PropertyValue > > ) {
159
- if ( typeof value === "number" && value && ! CSS_NUMBER [ name ] ) {
159
+ if ( typeof value === "number" && value && ! CSS_NUMBER . has ( name ) ) {
160
160
return `${ name } :${ value } px` ;
161
161
}
162
162
@@ -299,15 +299,15 @@ export class Cache<T extends Container<any>> {
299
299
300
300
protected sheet : string [ ] = [ ] ;
301
301
protected children : T [ ] = [ ] ;
302
- protected counters : Record < string , number | undefined > = Object . create ( null ) ;
302
+ protected counters = new Map < string , number > ( ) ;
303
303
304
304
constructor ( public changes ?: Changes ) { }
305
305
306
306
add ( style : T ) : void {
307
307
const id = style . cid ( ) ;
308
- const count = this . counters [ id ] || 0 ;
308
+ const count = this . counters . get ( id ) ?? 0 ;
309
309
310
- this . counters [ id ] = count + 1 ;
310
+ this . counters . set ( id , count + 1 ) ;
311
311
312
312
if ( count === 0 ) {
313
313
const item = style . clone ( ) ;
@@ -332,16 +332,14 @@ export class Cache<T extends Container<any>> {
332
332
333
333
remove ( style : T ) : void {
334
334
const id = style . cid ( ) ;
335
- const count = this . counters [ id ] ;
335
+ const count = this . counters . get ( id ) ;
336
336
337
337
if ( count ) {
338
- this . counters [ id ] = count - 1 ;
339
-
340
338
const index = this . children . findIndex ( ( x ) => x . cid ( ) === id ) ;
341
339
342
340
if ( count === 1 ) {
343
341
const item = this . children [ index ] ;
344
- delete this . counters [ id ] ;
342
+ this . counters . delete ( id ) ;
345
343
this . children . splice ( index , 1 ) ;
346
344
this . sheet . splice ( index , 1 ) ;
347
345
this . changeId ++ ;
@@ -350,6 +348,7 @@ export class Cache<T extends Container<any>> {
350
348
const item = this . children [ index ] as T & Cache < any > ;
351
349
const prevChangeId = item . changeId ;
352
350
351
+ this . counters . set ( id , count - 1 ) ;
353
352
item . unmerge ( style ) ;
354
353
355
354
if ( item . changeId !== prevChangeId ) {
0 commit comments