File tree 2 files changed +13
-8
lines changed
2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change 1
1
In next release ...
2
2
3
+ - Use lookup table to optimize ` get ` method.
4
+
3
5
- The ` connect ` method now returns a boolean status of whether the
4
6
connection is encrypted.
5
7
Original file line number Diff line number Diff line change @@ -8,22 +8,25 @@ type ResultHandler = (resolve: Resolver) => void;
8
8
type Callback < T > = ( item : T ) => void ;
9
9
10
10
export class ResultRow < T > {
11
- private readonly length : number ;
11
+ private readonly lookup : { [ name : string ] : number } ;
12
12
13
13
constructor ( public readonly names : string [ ] , public readonly data : T [ ] ) {
14
- this . length = names . length ;
14
+ const lookup : { [ name : string ] : number } = { } ;
15
+ let i = 0 ;
16
+ for ( const name of names ) {
17
+ lookup [ name ] = i ;
18
+ i ++ ;
19
+ }
20
+ this . lookup = lookup ;
15
21
}
16
22
17
23
[ Symbol . iterator ] ( ) : Iterator < T > {
18
- return this . data [ Symbol . iterator ] ( ) ;
24
+ return this . data [ Symbol . iterator ] ( ) ;
19
25
}
20
26
21
27
get ( name : string ) : T | undefined {
22
- for ( let i = 0 ; i < this . length ; i ++ ) {
23
- if ( this . names [ i ] === name ) {
24
- return this . data [ i ] ;
25
- }
26
- }
28
+ const i = this . lookup [ name ] ;
29
+ return this . data [ i ] ;
27
30
}
28
31
}
29
32
You can’t perform that action at this time.
0 commit comments