File tree 4 files changed +15
-9
lines changed
4 files changed +15
-9
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 @@ -50,7 +50,7 @@ export type ResultIterator = _ResultIterator<Value>;
50
50
51
51
export type ResultRow = _ResultRow < Value > ;
52
52
53
- export type Connect = ( Error | string | null ) ;
53
+ export type Connect = Error | null ;
54
54
55
55
export type End = void ;
56
56
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
Original file line number Diff line number Diff line change 15
15
"allowSyntheticDefaultImports" : true ,
16
16
"experimentalDecorators" : true ,
17
17
"emitDecoratorMetadata" : true ,
18
+ "noImplicitAny" : true ,
18
19
"noUnusedParameters" : true ,
19
20
"noUnusedLocals" : true ,
20
21
"declarationDir" : " dist" ,
You can’t perform that action at this time.
0 commit comments