1
- /**
2
- * Puts `key` into the backing array, if it is not already present. Returns
3
- * the index of the `key` in the backing array.
4
- */
5
- export let put : ( strarr : FastStringArray , key : string ) => number ;
6
-
7
1
/**
8
2
* FastStringArray acts like a `Set` (allowing only one occurrence of a string
9
3
* `key`), but provides the index of the `key` in the backing array.
@@ -15,21 +9,24 @@ export let put: (strarr: FastStringArray, key: string) => number;
15
9
export class FastStringArray {
16
10
indexes = Object . create ( null ) as { [ key : string ] : number } ;
17
11
array = [ ] as ReadonlyArray < string > ;
12
+ }
18
13
19
- static {
20
- put = ( strarr , key ) => {
21
- const { array, indexes } = strarr ;
22
- // The key may or may not be present. If it is present, it's a number.
23
- let index = indexes [ key ] as number | undefined ;
24
-
25
- // If it's not yet present, we need to insert it and track the index in the
26
- // indexes.
27
- if ( index === undefined ) {
28
- index = indexes [ key ] = array . length ;
29
- ( array as string [ ] ) . push ( key ) ;
30
- }
14
+ /**
15
+ * Puts `key` into the backing array, if it is not already present. Returns
16
+ * the index of the `key` in the backing array.
17
+ */
18
+ export function put ( strarr : FastStringArray , key : string ) : number {
19
+ const { array, indexes } = strarr ;
20
+ // The key may or may not be present. If it is present, it's a number.
21
+ let index = indexes [ key ] as number | undefined ;
31
22
32
- return index ;
33
- } ;
23
+ // If it's not yet present, we need to insert it and track the index in the
24
+ // indexes.
25
+ if ( index === undefined ) {
26
+ index = indexes [ key ] = array . length ;
27
+ ( array as string [ ] ) . push ( key ) ;
34
28
}
29
+
30
+ return index ;
35
31
}
32
+
0 commit comments