mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Do not construct arguments to _focusDebug when running in non-debug modes (#38463)
The time required to call FocusNode.toString and build _focusDebug messages was showing up in some performance benchmarks.
This commit is contained in:
parent
53d510a96e
commit
fe5651b846
@ -18,18 +18,16 @@ import 'framework.dart';
|
|||||||
// when focus changes occur.
|
// when focus changes occur.
|
||||||
const bool _kDebugFocus = false;
|
const bool _kDebugFocus = false;
|
||||||
|
|
||||||
void _focusDebug(String message, [Iterable<String> details]) {
|
bool _focusDebug(String message, [Iterable<String> details]) {
|
||||||
assert(() {
|
if (_kDebugFocus) {
|
||||||
if (_kDebugFocus) {
|
debugPrint('FOCUS: $message');
|
||||||
debugPrint('FOCUS: $message');
|
if (details != null && details.isNotEmpty) {
|
||||||
if (details != null && details.isNotEmpty) {
|
for (String detail in details) {
|
||||||
for (String detail in details) {
|
debugPrint(' $detail');
|
||||||
debugPrint(' $detail');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
}());
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Signature of a callback used by [Focus.onKey] and [FocusScope.onKey]
|
/// Signature of a callback used by [Focus.onKey] and [FocusScope.onKey]
|
||||||
@ -79,7 +77,7 @@ class FocusAttachment {
|
|||||||
/// Calling [FocusNode.dispose] will also automatically detach the node.
|
/// Calling [FocusNode.dispose] will also automatically detach the node.
|
||||||
void detach() {
|
void detach() {
|
||||||
assert(_node != null);
|
assert(_node != null);
|
||||||
_focusDebug('Detaching node:', <String>[_node.toString(), 'With enclosing scope ${_node.enclosingScope}']);
|
assert(_focusDebug('Detaching node:', <String>[_node.toString(), 'With enclosing scope ${_node.enclosingScope}']));
|
||||||
if (isAttached) {
|
if (isAttached) {
|
||||||
if (_node.hasPrimaryFocus) {
|
if (_node.hasPrimaryFocus) {
|
||||||
_node.unfocus();
|
_node.unfocus();
|
||||||
@ -1018,7 +1016,7 @@ class FocusManager with DiagnosticableTreeMixin {
|
|||||||
// Called to indicate that the given node is being disposed.
|
// Called to indicate that the given node is being disposed.
|
||||||
void _willDisposeFocusNode(FocusNode node) {
|
void _willDisposeFocusNode(FocusNode node) {
|
||||||
assert(node != null);
|
assert(node != null);
|
||||||
_focusDebug('Disposing of node:', <String>[node.toString(), 'with enclosing scope ${node.enclosingScope}']);
|
assert(_focusDebug('Disposing of node:', <String>[node.toString(), 'with enclosing scope ${node.enclosingScope}']));
|
||||||
_willUnfocusNode(node);
|
_willUnfocusNode(node);
|
||||||
_dirtyNodes.remove(node);
|
_dirtyNodes.remove(node);
|
||||||
}
|
}
|
||||||
@ -1027,7 +1025,7 @@ class FocusManager with DiagnosticableTreeMixin {
|
|||||||
// pending request to be focused should be canceled.
|
// pending request to be focused should be canceled.
|
||||||
void _willUnfocusNode(FocusNode node) {
|
void _willUnfocusNode(FocusNode node) {
|
||||||
assert(node != null);
|
assert(node != null);
|
||||||
_focusDebug('Unfocusing node $node');
|
assert(_focusDebug('Unfocusing node $node'));
|
||||||
if (_primaryFocus == node) {
|
if (_primaryFocus == node) {
|
||||||
_primaryFocus = null;
|
_primaryFocus = null;
|
||||||
_dirtyNodes.add(node);
|
_dirtyNodes.add(node);
|
||||||
@ -1038,7 +1036,7 @@ class FocusManager with DiagnosticableTreeMixin {
|
|||||||
_dirtyNodes.add(node);
|
_dirtyNodes.add(node);
|
||||||
_markNeedsUpdate();
|
_markNeedsUpdate();
|
||||||
}
|
}
|
||||||
_focusDebug('Unfocused node $node:', <String>['primary focus is $_primaryFocus', 'next focus will be $_nextFocus']);
|
assert(_focusDebug('Unfocused node $node:', <String>['primary focus is $_primaryFocus', 'next focus will be $_nextFocus']));
|
||||||
}
|
}
|
||||||
|
|
||||||
// True indicates that there is an update pending.
|
// True indicates that there is an update pending.
|
||||||
@ -1050,7 +1048,7 @@ class FocusManager with DiagnosticableTreeMixin {
|
|||||||
// If newFocus isn't specified, then don't mess with _nextFocus, just
|
// If newFocus isn't specified, then don't mess with _nextFocus, just
|
||||||
// schedule the update.
|
// schedule the update.
|
||||||
_nextFocus = newFocus ?? _nextFocus;
|
_nextFocus = newFocus ?? _nextFocus;
|
||||||
_focusDebug('Scheduling update, next focus will be $_nextFocus');
|
assert(_focusDebug('Scheduling update, next focus will be $_nextFocus'));
|
||||||
if (_haveScheduledUpdate) {
|
if (_haveScheduledUpdate) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1060,7 +1058,7 @@ class FocusManager with DiagnosticableTreeMixin {
|
|||||||
|
|
||||||
void _applyFocusChange() {
|
void _applyFocusChange() {
|
||||||
_haveScheduledUpdate = false;
|
_haveScheduledUpdate = false;
|
||||||
_focusDebug('Refreshing focus state. Next focus will be $_nextFocus');
|
assert(_focusDebug('Refreshing focus state. Next focus will be $_nextFocus'));
|
||||||
final FocusNode previousFocus = _primaryFocus;
|
final FocusNode previousFocus = _primaryFocus;
|
||||||
if (_primaryFocus == null && _nextFocus == null) {
|
if (_primaryFocus == null && _nextFocus == null) {
|
||||||
// If we don't have any current focus, and nobody has asked to focus yet,
|
// If we don't have any current focus, and nobody has asked to focus yet,
|
||||||
@ -1078,7 +1076,7 @@ class FocusManager with DiagnosticableTreeMixin {
|
|||||||
_nextFocus = null;
|
_nextFocus = null;
|
||||||
}
|
}
|
||||||
if (previousFocus != _primaryFocus) {
|
if (previousFocus != _primaryFocus) {
|
||||||
_focusDebug('Updating focus from $previousFocus to $_primaryFocus');
|
assert(_focusDebug('Updating focus from $previousFocus to $_primaryFocus'));
|
||||||
if (previousFocus != null) {
|
if (previousFocus != null) {
|
||||||
_dirtyNodes.add(previousFocus);
|
_dirtyNodes.add(previousFocus);
|
||||||
}
|
}
|
||||||
@ -1086,7 +1084,7 @@ class FocusManager with DiagnosticableTreeMixin {
|
|||||||
_dirtyNodes.add(_primaryFocus);
|
_dirtyNodes.add(_primaryFocus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_focusDebug('Notifying ${_dirtyNodes.length} dirty nodes:', _dirtyNodes.toList().map<String>((FocusNode node) => node.toString()));
|
assert(_focusDebug('Notifying ${_dirtyNodes.length} dirty nodes:', _dirtyNodes.toList().map<String>((FocusNode node) => node.toString())));
|
||||||
for (FocusNode node in _dirtyNodes) {
|
for (FocusNode node in _dirtyNodes) {
|
||||||
node._notify();
|
node._notify();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user