Commit 8bcf302e authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

use conditional assignment (#9252)

parent 3eb87830
...@@ -60,9 +60,7 @@ abstract class SyntaxHighlighter { // ignore: one_member_abstracts ...@@ -60,9 +60,7 @@ abstract class SyntaxHighlighter { // ignore: one_member_abstracts
class DartSyntaxHighlighter extends SyntaxHighlighter { class DartSyntaxHighlighter extends SyntaxHighlighter {
DartSyntaxHighlighter([this._style]) { DartSyntaxHighlighter([this._style]) {
_spans = <_HighlightSpan>[]; _spans = <_HighlightSpan>[];
_style ??= SyntaxHighlighterStyle.darkThemeStyle();
if (_style == null)
_style = SyntaxHighlighterStyle.darkThemeStyle();
} }
SyntaxHighlighterStyle _style; SyntaxHighlighterStyle _style;
......
...@@ -78,8 +78,7 @@ Duration timeBase; ...@@ -78,8 +78,7 @@ Duration timeBase;
RenderTransform transformBox; RenderTransform transformBox;
void rotate(Duration timeStamp) { void rotate(Duration timeStamp) {
if (timeBase == null) timeBase ??= timeStamp;
timeBase = timeStamp;
final double delta = (timeStamp - timeBase).inMicroseconds.toDouble() / Duration.MICROSECONDS_PER_SECOND; // radians final double delta = (timeStamp - timeBase).inMicroseconds.toDouble() / Duration.MICROSECONDS_PER_SECOND; // radians
transformBox.setIdentity(); transformBox.setIdentity();
......
...@@ -577,10 +577,8 @@ class BoxShadow { ...@@ -577,10 +577,8 @@ class BoxShadow {
static List<BoxShadow> lerpList(List<BoxShadow> a, List<BoxShadow> b, double t) { static List<BoxShadow> lerpList(List<BoxShadow> a, List<BoxShadow> b, double t) {
if (a == null && b == null) if (a == null && b == null)
return null; return null;
if (a == null) a ??= <BoxShadow>[];
a = <BoxShadow>[]; b ??= <BoxShadow>[];
if (b == null)
b = <BoxShadow>[];
final List<BoxShadow> result = <BoxShadow>[]; final List<BoxShadow> result = <BoxShadow>[];
final int commonLength = math.min(a.length, b.length); final int commonLength = math.min(a.length, b.length);
for (int i = 0; i < commonLength; ++i) for (int i = 0; i < commonLength; ++i)
......
...@@ -1482,8 +1482,7 @@ abstract class RenderBox extends RenderObject { ...@@ -1482,8 +1482,7 @@ abstract class RenderBox extends RenderObject {
@mustCallSuper @mustCallSuper
double getDistanceToActualBaseline(TextBaseline baseline) { double getDistanceToActualBaseline(TextBaseline baseline) {
assert(_debugDoingBaseline); assert(_debugDoingBaseline);
if (_cachedBaselines == null) _cachedBaselines ??= <TextBaseline, double>{};
_cachedBaselines = <TextBaseline, double>{};
_cachedBaselines.putIfAbsent(baseline, () => computeDistanceToActualBaseline(baseline)); _cachedBaselines.putIfAbsent(baseline, () => computeDistanceToActualBaseline(baseline));
return _cachedBaselines[baseline]; return _cachedBaselines[baseline];
} }
......
...@@ -203,8 +203,7 @@ class ContainerLayer extends Layer { ...@@ -203,8 +203,7 @@ class ContainerLayer extends Layer {
if (_lastChild != null) if (_lastChild != null)
_lastChild._nextSibling = child; _lastChild._nextSibling = child;
_lastChild = child; _lastChild = child;
if (_firstChild == null) _firstChild ??= child;
_firstChild = child;
} }
void _remove(Layer child) { void _remove(Layer child) {
......
...@@ -2697,8 +2697,7 @@ abstract class ContainerRenderObjectMixin<ChildType extends RenderObject, Parent ...@@ -2697,8 +2697,7 @@ abstract class ContainerRenderObjectMixin<ChildType extends RenderObject, Parent
_firstChildParentData.previousSibling = child; _firstChildParentData.previousSibling = child;
} }
_firstChild = child; _firstChild = child;
if (_lastChild == null) _lastChild ??= child;
_lastChild = child;
} else { } else {
assert(_firstChild != null); assert(_firstChild != null);
assert(_lastChild != null); assert(_lastChild != null);
......
...@@ -199,8 +199,7 @@ class Ticker { ...@@ -199,8 +199,7 @@ class Ticker {
assert(scheduled); assert(scheduled);
_animationId = null; _animationId = null;
if (_startTime == null) _startTime ??= timeStamp;
_startTime = timeStamp;
_onTick(timeStamp - _startTime); _onTick(timeStamp - _startTime);
......
...@@ -132,8 +132,7 @@ class FocusScopeNode extends Object with TreeDiagnosticsMixin { ...@@ -132,8 +132,7 @@ class FocusScopeNode extends Object with TreeDiagnosticsMixin {
if (_firstChild != null) if (_firstChild != null)
_firstChild._previousSibling = child; _firstChild._previousSibling = child;
_firstChild = child; _firstChild = child;
if (_lastChild == null) _lastChild ??= child;
_lastChild = child;
child._updateManager(_manager); child._updateManager(_manager);
} }
......
...@@ -24,8 +24,7 @@ class TestGestureFlutterBinding extends BindingBase with GestureBinding { ...@@ -24,8 +24,7 @@ class TestGestureFlutterBinding extends BindingBase with GestureBinding {
TestGestureFlutterBinding _binding = new TestGestureFlutterBinding(); TestGestureFlutterBinding _binding = new TestGestureFlutterBinding();
void ensureTestGestureBinding() { void ensureTestGestureBinding() {
if (_binding == null) _binding ??= new TestGestureFlutterBinding();
_binding = new TestGestureFlutterBinding();
assert(GestureBinding.instance != null); assert(GestureBinding.instance != null);
} }
......
...@@ -430,12 +430,7 @@ class AndroidDevice extends Device { ...@@ -430,12 +430,7 @@ class AndroidDevice extends Device {
} }
@override @override
DevicePortForwarder get portForwarder { DevicePortForwarder get portForwarder => _portForwarder ??= new _AndroidDevicePortForwarder(this);
if (_portForwarder == null)
_portForwarder = new _AndroidDevicePortForwarder(this);
return _portForwarder;
}
static final RegExp _timeRegExp = new RegExp(r'^\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}', multiLine: true); static final RegExp _timeRegExp = new RegExp(r'^\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}', multiLine: true);
......
...@@ -116,8 +116,7 @@ class _PosixUtils extends OperatingSystemUtils { ...@@ -116,8 +116,7 @@ class _PosixUtils extends OperatingSystemUtils {
.trim()} ${results[2].stdout.trim()}"; .trim()} ${results[2].stdout.trim()}";
} }
} }
if (_name == null) _name ??= super.name;
_name = super.name;
} }
return _name; return _name;
} }
......
...@@ -86,12 +86,7 @@ class Cache { ...@@ -86,12 +86,7 @@ class Cache {
static String _dartSdkVersion; static String _dartSdkVersion;
static String get dartSdkVersion { static String get dartSdkVersion => _dartSdkVersion ??= platform.version;
if (_dartSdkVersion == null) {
_dartSdkVersion = platform.version;
}
return _dartSdkVersion;
}
static String _engineRevision; static String _engineRevision;
......
...@@ -724,8 +724,7 @@ class AppInstance { ...@@ -724,8 +724,7 @@ class AppInstance {
} }
dynamic _runInZone(AppDomain domain, dynamic method()) { dynamic _runInZone(AppDomain domain, dynamic method()) {
if (_logger == null) _logger ??= new _AppRunLogger(domain, this, logToStdout: logToStdout);
_logger = new _AppRunLogger(domain, this, logToStdout: logToStdout);
final AppContext appContext = new AppContext(); final AppContext appContext = new AppContext();
appContext.setVariable(Logger, _logger); appContext.setVariable(Logger, _logger);
......
...@@ -34,8 +34,7 @@ Future<Null> pubGet({ ...@@ -34,8 +34,7 @@ Future<Null> pubGet({
bool offline: false, bool offline: false,
bool checkLastModified: true bool checkLastModified: true
}) async { }) async {
if (directory == null) directory ??= fs.currentDirectory.path;
directory = fs.currentDirectory.path;
final File pubSpecYaml = fs.file(fs.path.join(directory, 'pubspec.yaml')); final File pubSpecYaml = fs.file(fs.path.join(directory, 'pubspec.yaml'));
final File dotPackages = fs.file(fs.path.join(directory, '.packages')); final File dotPackages = fs.file(fs.path.join(directory, '.packages'));
......
...@@ -97,8 +97,7 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery { ...@@ -97,8 +97,7 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
void startPolling() { void startPolling() {
if (_timer == null) { if (_timer == null) {
if (_items == null) _items ??= new ItemListNotifier<Device>();
_items = new ItemListNotifier<Device>();
_timer = new Timer.periodic(_pollingDuration, (Timer timer) { _timer = new Timer.periodic(_pollingDuration, (Timer timer) {
_items.updateWithNewList(pollingGetDevices()); _items.updateWithNewList(pollingGetDevices());
}); });
...@@ -112,20 +111,17 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery { ...@@ -112,20 +111,17 @@ abstract class PollingDeviceDiscovery extends DeviceDiscovery {
@override @override
List<Device> get devices { List<Device> get devices {
if (_items == null) _items ??= new ItemListNotifier<Device>.from(pollingGetDevices());
_items = new ItemListNotifier<Device>.from(pollingGetDevices());
return _items.items; return _items.items;
} }
Stream<Device> get onAdded { Stream<Device> get onAdded {
if (_items == null) _items ??= new ItemListNotifier<Device>();
_items = new ItemListNotifier<Device>();
return _items.onAdded; return _items.onAdded;
} }
Stream<Device> get onRemoved { Stream<Device> get onRemoved {
if (_items == null) _items ??= new ItemListNotifier<Device>();
_items = new ItemListNotifier<Device>();
return _items.onRemoved; return _items.onRemoved;
} }
......
...@@ -357,12 +357,7 @@ class IOSDevice extends Device { ...@@ -357,12 +357,7 @@ class IOSDevice extends Device {
} }
@override @override
DevicePortForwarder get portForwarder { DevicePortForwarder get portForwarder => _portForwarder ??= new _IOSDevicePortForwarder(this);
if (_portForwarder == null)
_portForwarder = new _IOSDevicePortForwarder(this);
return _portForwarder;
}
@override @override
void clearLogs() { void clearLogs() {
......
...@@ -565,12 +565,7 @@ class IOSSimulator extends Device { ...@@ -565,12 +565,7 @@ class IOSSimulator extends Device {
} }
@override @override
DevicePortForwarder get portForwarder { DevicePortForwarder get portForwarder => _portForwarder ??= new _IOSSimulatorDevicePortForwarder(this);
if (_portForwarder == null)
_portForwarder = new _IOSSimulatorDevicePortForwarder(this);
return _portForwarder;
}
@override @override
void clearLogs() { void clearLogs() {
......
...@@ -406,8 +406,7 @@ class OperationResult { ...@@ -406,8 +406,7 @@ class OperationResult {
/// Given the value of the --target option, return the path of the Dart file /// Given the value of the --target option, return the path of the Dart file
/// where the app's main function should be. /// where the app's main function should be.
String findMainDartFile([String target]) { String findMainDartFile([String target]) {
if (target == null) target ??= '';
target = '';
final String targetPath = fs.path.absolute(target); final String targetPath = fs.path.absolute(target);
if (fs.isDirectorySync(targetPath)) if (fs.isDirectorySync(targetPath))
return fs.path.join(targetPath, 'lib', 'main.dart'); return fs.path.join(targetPath, 'lib', 'main.dart');
......
...@@ -286,8 +286,7 @@ class FlutterCommandRunner extends CommandRunner<Null> { ...@@ -286,8 +286,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
engineSourcePath = null; engineSourcePath = null;
} }
if (engineSourcePath == null) engineSourcePath ??= _tryEnginePath(fs.path.join(Cache.flutterRoot, '../engine/src'));
engineSourcePath = _tryEnginePath(fs.path.join(Cache.flutterRoot, '../engine/src'));
if (engineSourcePath == null) { if (engineSourcePath == null) {
printError('Unable to detect local Flutter engine build directory.\n' printError('Unable to detect local Flutter engine build directory.\n'
...@@ -327,8 +326,7 @@ class FlutterCommandRunner extends CommandRunner<Null> { ...@@ -327,8 +326,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
} }
static void initFlutterRoot() { static void initFlutterRoot() {
if (Cache.flutterRoot == null) Cache.flutterRoot ??= _defaultFlutterRoot;
Cache.flutterRoot = _defaultFlutterRoot;
} }
/// Get all pub packages in the Flutter repo. /// Get all pub packages in the Flutter repo.
......
...@@ -266,11 +266,9 @@ abstract class ServiceObject { ...@@ -266,11 +266,9 @@ abstract class ServiceObject {
serviceObject = new Isolate._empty(owner.vm); serviceObject = new Isolate._empty(owner.vm);
break; break;
} }
if (serviceObject == null) {
// If we don't have a model object for this service object type, as a // If we don't have a model object for this service object type, as a
// fallback return a ServiceMap object. // fallback return a ServiceMap object.
serviceObject = new ServiceMap._empty(owner); serviceObject ??= new ServiceMap._empty(owner);
}
// We have now constructed an emtpy service object, call update to // We have now constructed an emtpy service object, call update to
// populate it. // populate it.
serviceObject.update(map); serviceObject.update(map);
......
...@@ -43,19 +43,12 @@ class RecordingVMServiceChannel extends DelegatingStreamChannel<String> { ...@@ -43,19 +43,12 @@ class RecordingVMServiceChannel extends DelegatingStreamChannel<String> {
@override @override
Stream<String> get stream { Stream<String> get stream {
if (_streamRecorder == null) { _streamRecorder ??= new _RecordingStream(super.stream, _messages);
_streamRecorder = new _RecordingStream(super.stream, _messages);
}
return _streamRecorder.stream; return _streamRecorder.stream;
} }
@override @override
StreamSink<String> get sink { StreamSink<String> get sink => _sinkRecorder ??= new _RecordingSink(super.sink, _messages);
if (_sinkRecorder == null) {
_sinkRecorder = new _RecordingSink(super.sink, _messages);
}
return _sinkRecorder;
}
} }
/// Base class for request and response JSON-rpc messages. /// Base class for request and response JSON-rpc messages.
...@@ -250,11 +243,7 @@ class ReplayVMServiceChannel extends StreamChannelMixin<String> { ...@@ -250,11 +243,7 @@ class ReplayVMServiceChannel extends StreamChannelMixin<String> {
} }
@override @override
StreamSink<String> get sink { StreamSink<String> get sink => _replaySink ??= new _ReplaySink(this);
if (_replaySink == null)
_replaySink = new _ReplaySink(this);
return _replaySink;
}
@override @override
Stream<String> get stream => _controller.stream; Stream<String> get stream => _controller.stream;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment