File tree Expand file tree Collapse file tree 12 files changed +0
-153
lines changed
Expand file tree Collapse file tree 12 files changed +0
-153
lines changed Original file line number Diff line number Diff line change @@ -76,29 +76,6 @@ export class AnyType extends AbstractType<schema.AnySchema> {
7676 this . codegenBinaryEncoder ( ctx , value ) ;
7777 }
7878
79- public codegenCapacityEstimator ( ctx : CapacityEstimatorCodegenContext , value : JsExpression ) : void {
80- const codegen = ctx . codegen ;
81- codegen . link ( 'Value' ) ;
82- const r = codegen . var ( value . use ( ) ) ;
83- codegen . if (
84- `${ r } instanceof Value` ,
85- ( ) => {
86- codegen . if (
87- `${ r } .type` ,
88- ( ) => {
89- ctx . codegen . js ( `size += ${ r } .type.capacityEstimator()(${ r } .data);` ) ;
90- } ,
91- ( ) => {
92- ctx . codegen . js ( `size += maxEncodingCapacity(${ r } .data);` ) ;
93- } ,
94- ) ;
95- } ,
96- ( ) => {
97- ctx . codegen . js ( `size += maxEncodingCapacity(${ r } );` ) ;
98- } ,
99- ) ;
100- }
101-
10279 public toTypeScriptAst ( ) : ts . TsType {
10380 return { node : 'AnyKeyword' } ;
10481 }
Original file line number Diff line number Diff line change @@ -152,27 +152,6 @@ export class ArrayType<T extends Type> extends AbstractType<schema.ArraySchema<S
152152 ) ;
153153 }
154154
155- public codegenCapacityEstimator ( ctx : CapacityEstimatorCodegenContext , value : JsExpression ) : void {
156- const codegen = ctx . codegen ;
157- ctx . inc ( MaxEncodingOverhead . Array ) ;
158- const rLen = codegen . var ( `${ value . use ( ) } .length` ) ;
159- const type = this . type ;
160- codegen . js ( `size += ${ MaxEncodingOverhead . ArrayElement } * ${ rLen } ` ) ;
161- const fn = type . compileCapacityEstimator ( {
162- system : ctx . options . system ,
163- name : ctx . options . name ,
164- } ) ;
165- const isConstantSizeType = type instanceof ConstType || type instanceof BooleanType || type instanceof NumberType ;
166- if ( isConstantSizeType ) {
167- codegen . js ( `size += ${ rLen } * ${ fn ( null ) } ;` ) ;
168- } else {
169- const r = codegen . var ( value . use ( ) ) ;
170- const rFn = codegen . linkDependency ( fn ) ;
171- const ri = codegen . getRegister ( ) ;
172- codegen . js ( `for(var ${ ri } = ${ rLen } ; ${ ri } -- !== 0;) size += ${ rFn } (${ r } [${ ri } ]);` ) ;
173- }
174- }
175-
176155 public toTypeScriptAst ( ) : ts . TsArrayType {
177156 return {
178157 node : 'ArrayType' ,
Original file line number Diff line number Diff line change @@ -115,11 +115,6 @@ export class BinaryType<T extends Type> extends AbstractType<schema.BinarySchema
115115 this . codegenBinaryEncoder ( ctx , value ) ;
116116 }
117117
118- public codegenCapacityEstimator ( ctx : CapacityEstimatorCodegenContext , value : JsExpression ) : void {
119- ctx . inc ( MaxEncodingOverhead . Binary ) ;
120- ctx . codegen . js ( `size += ${ MaxEncodingOverhead . BinaryLengthMultiplier } * ${ value . use ( ) } .length;` ) ;
121- }
122-
123118 public toTypeScriptAst ( ) : ts . TsGenericTypeAnnotation {
124119 return {
125120 node : 'GenericTypeAnnotation' ,
Original file line number Diff line number Diff line change @@ -56,10 +56,6 @@ export class BooleanType extends AbstractType<schema.BooleanSchema> {
5656 this . codegenBinaryEncoder ( ctx , value ) ;
5757 }
5858
59- public codegenCapacityEstimator ( ctx : CapacityEstimatorCodegenContext , value : JsExpression ) : void {
60- ctx . inc ( MaxEncodingOverhead . Boolean ) ;
61- }
62-
6359 public toTypeScriptAst ( ) : ts . TsBooleanKeyword {
6460 return { node : 'BooleanKeyword' } ;
6561 }
Original file line number Diff line number Diff line change @@ -75,10 +75,6 @@ export class ConstType<V = any> extends AbstractType<schema.ConstSchema<V>> {
7575 this . codegenBinaryEncoder ( ctx , value ) ;
7676 }
7777
78- public codegenCapacityEstimator ( ctx : CapacityEstimatorCodegenContext , value : JsExpression ) : void {
79- ctx . inc ( maxEncodingCapacity ( this . value ( ) ) ) ;
80- }
81-
8278 public toTypeScriptAst ( ) {
8379 const value = this . schema . value ;
8480 if ( value === null ) {
Original file line number Diff line number Diff line change @@ -141,30 +141,6 @@ export class MapType<T extends Type> extends AbstractType<schema.MapSchema<Schem
141141 ctx . blob ( objEndBlob ) ;
142142 }
143143
144- public codegenCapacityEstimator ( ctx : CapacityEstimatorCodegenContext , value : JsExpression ) : void {
145- const codegen = ctx . codegen ;
146- ctx . inc ( MaxEncodingOverhead . Object ) ;
147- const r = codegen . var ( value . use ( ) ) ;
148- const rKeys = codegen . var ( `Object.keys(${ r } )` ) ;
149- const rKey = codegen . var ( ) ;
150- const rLen = codegen . var ( `${ rKeys } .length` ) ;
151- codegen . js ( `size += ${ MaxEncodingOverhead . ObjectElement } * ${ rLen } ` ) ;
152- const type = this . type ;
153- const fn = type . compileCapacityEstimator ( {
154- system : ctx . options . system ,
155- name : ctx . options . name ,
156- } ) ;
157- const rFn = codegen . linkDependency ( fn ) ;
158- const ri = codegen . var ( '0' ) ;
159- codegen . js ( `for (; ${ ri } < ${ rLen } ; ${ ri } ++) {` ) ;
160- codegen . js ( `${ rKey } = ${ rKeys } [${ ri } ];` ) ;
161- codegen . js (
162- `size += ${ MaxEncodingOverhead . String } + ${ MaxEncodingOverhead . StringLengthMultiplier } * ${ rKey } .length;` ,
163- ) ;
164- codegen . js ( `size += ${ rFn } (${ r } [${ rKey } ]);` ) ;
165- codegen . js ( `}` ) ;
166- }
167-
168144 public toTypeScriptAst ( ) : ts . TsTypeReference {
169145 const node : ts . TsTypeReference = {
170146 node : 'TypeReference' ,
Original file line number Diff line number Diff line change @@ -152,10 +152,6 @@ export class NumberType extends AbstractType<schema.NumberSchema> {
152152 this . codegenBinaryEncoder ( ctx , value ) ;
153153 }
154154
155- public codegenCapacityEstimator ( ctx : CapacityEstimatorCodegenContext , value : JsExpression ) : void {
156- ctx . inc ( MaxEncodingOverhead . Number ) ;
157- }
158-
159155 public toTypeScriptAst ( ) : ts . TsNumberKeyword {
160156 return { node : 'NumberKeyword' } ;
161157 }
Original file line number Diff line number Diff line change @@ -480,28 +480,6 @@ if (${rLength}) {
480480 }
481481 }
482482
483- public codegenCapacityEstimator ( ctx : CapacityEstimatorCodegenContext , value : JsExpression ) : void {
484- const codegen = ctx . codegen ;
485- const r = codegen . var ( value . use ( ) ) ;
486- const encodeUnknownFields = ! ! this . schema . encodeUnknownFields ;
487- if ( encodeUnknownFields ) {
488- codegen . js ( `size += maxEncodingCapacity(${ r } );` ) ;
489- return ;
490- }
491- const fields = this . fields ;
492- const overhead = MaxEncodingOverhead . Object + fields . length * MaxEncodingOverhead . ObjectElement ;
493- ctx . inc ( overhead ) ;
494- for ( const field of fields ) {
495- ctx . inc ( maxEncodingCapacity ( field . key ) ) ;
496- const accessor = normalizeAccessor ( field . key ) ;
497- const isOptional = field instanceof ObjectOptionalFieldType ;
498- const block = ( ) => field . value . codegenCapacityEstimator ( ctx , new JsExpression ( ( ) => `${ r } ${ accessor } ` ) ) ;
499- if ( isOptional ) {
500- codegen . if ( `${ r } ${ accessor } !== undefined` , block ) ;
501- } else block ( ) ;
502- }
503- }
504-
505483 public toTypeScriptAst ( ) : ts . TsTypeLiteral {
506484 const node : ts . TsTypeLiteral = {
507485 node : 'TypeLiteral' ,
Original file line number Diff line number Diff line change @@ -138,22 +138,6 @@ export class OrType<T extends Type[]> extends AbstractType<schema.OrSchema<{[K i
138138 this . codegenBinaryEncoder ( ctx , value ) ;
139139 }
140140
141- public codegenCapacityEstimator ( ctx : CapacityEstimatorCodegenContext , value : JsExpression ) : void {
142- const codegen = ctx . codegen ;
143- const discriminator = this . discriminator ( ) ;
144- const d = codegen . linkDependency ( discriminator ) ;
145- const types = this . types ;
146- codegen . switch (
147- `${ d } (${ value . use ( ) } )` ,
148- types . map ( ( type , index ) => [
149- index ,
150- ( ) => {
151- type . codegenCapacityEstimator ( ctx , value ) ;
152- } ,
153- ] ) ,
154- ) ;
155- }
156-
157141 public toTypeScriptAst ( ) : ts . TsUnionType {
158142 const node : ts . TsUnionType = {
159143 node : 'UnionType' ,
Original file line number Diff line number Diff line change @@ -118,14 +118,6 @@ export class RefType<T extends Type> extends AbstractType<schema.RefSchema<Schem
118118 this . codegenBinaryEncoder ( ctx , value ) ;
119119 }
120120
121- public codegenCapacityEstimator ( ctx : CapacityEstimatorCodegenContext , value : JsExpression ) : void {
122- const system = ctx . options . system || this . system ;
123- if ( ! system ) throw new Error ( 'NO_SYSTEM' ) ;
124- const estimator = system . resolve ( this . schema . ref ) . type . capacityEstimator ( ) ;
125- const d = ctx . codegen . linkDependency ( estimator ) ;
126- ctx . codegen . js ( `size += ${ d } (${ value . use ( ) } );` ) ;
127- }
128-
129121 public toTypeScriptAst ( ) : ts . TsGenericTypeAnnotation {
130122 return {
131123 node : 'GenericTypeAnnotation' ,
You can’t perform that action at this time.
0 commit comments