2025-08-01 11:20:23 +03:00
|
|
|
|
// ignore: depend_on_referenced_packages
|
2025-08-01 08:26:33 +03:00
|
|
|
|
import 'package:benchmark_harness/benchmark_harness.dart';
|
|
|
|
|
|
import 'package:cherrypick/cherrypick.dart';
|
2025-08-06 13:29:23 +03:00
|
|
|
|
import 'benchmark_utils.dart';
|
2025-08-01 08:26:33 +03:00
|
|
|
|
|
|
|
|
|
|
class Shared {}
|
2025-08-06 13:29:23 +03:00
|
|
|
|
|
2025-08-01 08:26:33 +03:00
|
|
|
|
class ParentImpl extends Shared {}
|
2025-08-06 13:29:23 +03:00
|
|
|
|
|
2025-08-01 08:26:33 +03:00
|
|
|
|
class ChildImpl extends Shared {}
|
|
|
|
|
|
|
|
|
|
|
|
class ParentModule extends Module {
|
|
|
|
|
|
@override
|
|
|
|
|
|
void builder(Scope currentScope) {
|
|
|
|
|
|
bind<Shared>().toProvide(() => ParentImpl()).singleton();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ChildOverrideModule extends Module {
|
|
|
|
|
|
@override
|
|
|
|
|
|
void builder(Scope currentScope) {
|
|
|
|
|
|
bind<Shared>().toProvide(() => ChildImpl()).singleton();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-06 13:29:23 +03:00
|
|
|
|
class ScopeOverrideBenchmark extends BenchmarkBase with BenchmarkWithScope {
|
2025-08-01 08:26:33 +03:00
|
|
|
|
ScopeOverrideBenchmark() : super('ScopeOverride (child overrides parent)');
|
|
|
|
|
|
late Scope child;
|
2025-08-06 13:29:23 +03:00
|
|
|
|
|
2025-08-01 08:26:33 +03:00
|
|
|
|
@override
|
|
|
|
|
|
void setup() {
|
2025-08-06 13:29:23 +03:00
|
|
|
|
setupScope([ParentModule()]);
|
|
|
|
|
|
child = scope.openSubScope('child');
|
2025-08-01 08:26:33 +03:00
|
|
|
|
child.installModules([ChildOverrideModule()]);
|
|
|
|
|
|
}
|
2025-08-06 13:29:23 +03:00
|
|
|
|
|
2025-08-01 08:26:33 +03:00
|
|
|
|
@override
|
|
|
|
|
|
void teardown() {
|
2025-08-06 13:29:23 +03:00
|
|
|
|
teardownScope();
|
2025-08-01 08:26:33 +03:00
|
|
|
|
}
|
2025-08-06 13:29:23 +03:00
|
|
|
|
|
2025-08-01 08:26:33 +03:00
|
|
|
|
@override
|
|
|
|
|
|
void run() {
|
|
|
|
|
|
// Должен возвращать ChildImpl, а не ParentImpl
|
|
|
|
|
|
final resolved = child.resolve<Shared>();
|
|
|
|
|
|
assert(resolved is ChildImpl);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|