Commit 7f2cbf3
Share a single SwitchingProvider instance across SingleCheck and DoubleCheck providers in fastInit mode.
Previously in Dagger's fastInit mode, each scoped provider (SingleCheck, DoubleCheck) or assisted factory instantiated a dedicated SwitchingProvider instance:
```java
this.fooFactoryProvider = SingleCheck.provider(new SwitchingProvider<>(testComponentImpl, 0));
```
This change introduces `dagger.internal.SwitchingProvider` and shares a single `SwitchingProvider` instance across all scoped and assisted factory bindings within a component:
1. Introduce the `dagger.internal.SwitchingProvider<T>` interface with a parameterized `T get(int id)` method.
2. Add `provider(SwitchingProvider<?>, int)` overloads to `SingleCheck` and `DoubleCheck`.
3. In component implementations, generate a single shared `private SwitchingProvider<Object> switchingProvider` instance initialized in `initialize()` and passed to `SingleCheck.provider` and `DoubleCheck.provider`.
4. Unscoped bindings continue to instantiate `SwitchingProvider` directly as a `Provider<T>`.
This reduces redundant SwitchingProvider object allocations during component initialization in fastInit mode.
RELNOTES=n/a
PiperOrigin-RevId: 9445829461 parent 4fbc045 commit 7f2cbf3
130 files changed
Lines changed: 2171 additions & 949 deletions
File tree
- dagger-compiler/main/java/dagger/internal/codegen
- writing
- xprocessing
- dagger-runtime
- api
- main/java/dagger/internal
- test/javatests/dagger/internal
- javatests/dagger/internal/codegen/goldens
- AssistedFactoryTest
- assistedParamConflictsWithComponentFieldName_successfulyDeduped
- testAssistedFactoryCycle
- testAssistedFactory_nullableAssistedParam
- testAssistedFactory
- testMultipleAssistedFactoryInDifferentComponents
- testParameterizedAssistParam
- BindsExplicitForInjectTest/testUnscopedBinds_succeeds
- ComponentBuilderTest/testNullableAnnotationsInGeneratedCode
- ComponentProcessorTest
- arrayComponentDependency
- componentDependency
- componentMethodInChildCallsComponentMethodInParent
- componentWithNullableDependency
- componentWithScope
- dependencyNameCollision
- primitiveComponentDependency
- privateMethodUsedOnlyInChildDoesNotUseQualifiedThis
- providerComponentType
- simpleComponent
- ComponentProtectedTypeTest/componentAccessesProtectedType_succeeds
- ComponentRequirementFieldTest/componentRequirementNeededInFactoryCreationOfSubcomponent
- ComponentShardTest
- testNewShardCreatedWithDependencies
- testNewShardCreated
- testNewShardSubcomponentCreated
- DaggerProcessingOptionsTest
- testCmdLineOptionEnabledPrecedesAnnotationDisabled
- testFastInitEnabledFromAnnotationSucceeded
- DelegateRequestRepresentationTest
- castNeeded_rawTypes_Provider_get
- castedToRawType
- doubleBinds
- frameworkRequestOnDelegateWithMixedScopes
- frameworkRequestOnDelegate
- inlineFactoryOfInacessibleType
- noCast_rawTypes_Provider_get_toInaccessibleType
- providerWhenBindsScopeGreaterThanDependencyScope
- toDoubleCheck
- toSingleCheck
- toUnscoped
- ElidedFactoriesTest
- scopedBinding_onlyUsedInSubcomponent
- simpleComponent_injectsProviderOf_dependsOnScoped
- InaccessibleTypeBindsTest
- inaccessibleTypeBoundInALoopScoped
- inaccessibleTypeBoundInALoop
- scopedInaccessibleTypeBound
- LazyClassKeyMapBindingComponentProcessorTest/mapBindingsWithInaccessibleKeys
- MapBindingComponentProcessorTest
- mapBindingsWithEnumKey
- mapBindingsWithInaccessibleKeys
- mapBindingsWithNonProviderValue
- mapBindingsWithStringKey
- mapBindingsWithWrappedKey
- MapRequestRepresentationTest
- lazyMaps
- mapBindings
- MapRequestRepresentationWithGuavaTest
- lazyMaps
- mapBindings
- MembersInjectionTest/accessibleRawType_ofInaccessibleType
- OptionalBindingRequestFulfillmentTest/inlinedOptionalBindings
- ProductionComponentProcessorTest
- productionScope_injectConstructor
- simpleComponent
- SubcomponentValidationTest/delegateFactoryNotCreatedForSubcomponentWhenProviderExistsInParent
- SwitchingProviderTest
- optionals
- scopedBinds
- switchingProviderTest
- unscopedBinds
- TypeUseNullableTest/componentDependencyWithTypeUseNullableType
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
499 | | - | |
| 499 | + | |
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| |||
Lines changed: 1 addition & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | | - | |
24 | 22 | | |
25 | 23 | | |
26 | 24 | | |
27 | | - | |
28 | 25 | | |
29 | 26 | | |
30 | | - | |
31 | 27 | | |
32 | 28 | | |
33 | 29 | | |
34 | 30 | | |
35 | 31 | | |
36 | 32 | | |
37 | 33 | | |
38 | | - | |
39 | 34 | | |
40 | 35 | | |
41 | 36 | | |
| |||
56 | 51 | | |
57 | 52 | | |
58 | 53 | | |
59 | | - | |
60 | | - | |
| 54 | + | |
61 | 55 | | |
62 | 56 | | |
63 | 57 | | |
64 | 58 | | |
65 | 59 | | |
66 | 60 | | |
67 | 61 | | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | 62 | | |
87 | 63 | | |
88 | 64 | | |
| |||
Lines changed: 80 additions & 40 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
31 | 30 | | |
32 | 31 | | |
33 | 32 | | |
| |||
37 | 36 | | |
38 | 37 | | |
39 | 38 | | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
| |||
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
52 | | - | |
53 | 51 | | |
54 | 52 | | |
55 | 53 | | |
| |||
75 | 73 | | |
76 | 74 | | |
77 | 75 | | |
78 | | - | |
79 | 76 | | |
80 | 77 | | |
81 | 78 | | |
82 | 79 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
| 80 | + | |
87 | 81 | | |
88 | 82 | | |
89 | | - | |
90 | 83 | | |
91 | 84 | | |
92 | 85 | | |
| |||
114 | 107 | | |
115 | 108 | | |
116 | 109 | | |
117 | | - | |
| 110 | + | |
118 | 111 | | |
119 | 112 | | |
120 | 113 | | |
| |||
130 | 123 | | |
131 | 124 | | |
132 | 125 | | |
| 126 | + | |
133 | 127 | | |
134 | 128 | | |
135 | 129 | | |
| |||
144 | 138 | | |
145 | 139 | | |
146 | 140 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
155 | 184 | | |
156 | 185 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
166 | 190 | | |
167 | 191 | | |
168 | 192 | | |
169 | 193 | | |
170 | 194 | | |
171 | 195 | | |
172 | | - | |
| 196 | + | |
173 | 197 | | |
174 | 198 | | |
175 | 199 | | |
| |||
188 | 212 | | |
189 | 213 | | |
190 | 214 | | |
191 | | - | |
| 215 | + | |
192 | 216 | | |
193 | 217 | | |
194 | 218 | | |
| |||
199 | 223 | | |
200 | 224 | | |
201 | 225 | | |
202 | | - | |
| 226 | + | |
| 227 | + | |
203 | 228 | | |
204 | 229 | | |
205 | 230 | | |
| |||
208 | 233 | | |
209 | 234 | | |
210 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
211 | 247 | | |
212 | 248 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
221 | 260 | | |
222 | 261 | | |
223 | 262 | | |
224 | 263 | | |
225 | 264 | | |
226 | 265 | | |
227 | 266 | | |
| 267 | + | |
228 | 268 | | |
229 | 269 | | |
230 | 270 | | |
231 | | - | |
232 | 271 | | |
233 | 272 | | |
234 | 273 | | |
235 | 274 | | |
| 275 | + | |
236 | 276 | | |
237 | 277 | | |
238 | 278 | | |
239 | 279 | | |
240 | 280 | | |
241 | | - | |
| 281 | + | |
242 | 282 | | |
243 | 283 | | |
244 | 284 | | |
| |||
Lines changed: 8 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
90 | 97 | | |
91 | 98 | | |
92 | 99 | | |
| |||
378 | 385 | | |
379 | 386 | | |
380 | 387 | | |
381 | | - | |
382 | | - | |
| 388 | + | |
383 | 389 | | |
384 | 390 | | |
385 | 391 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
97 | 102 | | |
98 | 103 | | |
99 | 104 | | |
| |||
282 | 287 | | |
283 | 288 | | |
284 | 289 | | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
285 | 300 | | |
286 | 301 | | |
287 | 302 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | | - | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| 125 | + | |
0 commit comments