| 49 | } |
| 50 | |
| 51 | class GraphReducerImpl implements GraphReducer { |
| 52 | private classSize: ClassSize; |
| 53 | private classSizeService: ClassSizeService; |
| 54 | |
| 55 | /** |
| 56 | * Tracks nodes that have already been reduced. This is necessary to count Dagger modules |
| 57 | * just once. They may be a common dependency and counted multiple times. |
| 58 | */ |
| 59 | private reduced: Set<string>; |
| 60 | |
| 61 | constructor(classSizeService: ClassSizeService, initialKey: string) { |
| 62 | this.classSizeService = classSizeService; |
| 63 | this.reduced = new Set(); |
| 64 | |
| 65 | const classInfo = { |
| 66 | 'field_count': 0, |
| 67 | 'method_count': 0, |
| 68 | 'lambda_count': 0, |
| 69 | 'code_size': 0, |
| 70 | 'inner_class_count': 0 |
| 71 | } as ClassInfo; |
| 72 | this.classSize = new ClassSize(classInfo); |
| 73 | const parentClassSize = this.classSizeService.getClassSize(initialKey); |
| 74 | if (parentClassSize) { |
| 75 | this.classSize.add(parentClassSize); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | reduce(key: string) { |
| 80 | if (this.reduced.has(key)) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | this.reduced.add(key); |
| 85 | const childClassSize = this.classSizeService.getClassSize(key); |
| 86 | if (childClassSize) { |
| 87 | this.classSize.add(childClassSize); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | result(): Weight { |
| 92 | return { |
| 93 | value: Math.round(this.classSize.getMemorySize() / 1024), |
| 94 | largeThreshold: LARGE_THRESHOLD_KB, |
| 95 | smallThreshold: SMALL_THRESHOLD_KB, |
| 96 | summary: this.classSize.getSummary(), |
| 97 | unit: 'kB' |
| 98 | } as Weight; |
| 99 | } |
| 100 | } |
nothing calls this directly
no outgoing calls
no test coverage detected