Skip to content

Commit

Permalink
Use inlining annotations on important methods for all targets (#143923)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkustermann authored Feb 22, 2024
1 parent 44e440a commit b09ca49
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/flutter/lib/src/foundation/persistent_hash_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ abstract class _TrieNode {
static const int hashBitsPerLevel = 5;
static const int hashBitsPerLevelMask = (1 << hashBitsPerLevel) - 1;

@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
static int trieIndex(int hash, int bitIndex) {
return (hash >>> bitIndex) & hashBitsPerLevelMask;
}
Expand Down Expand Up @@ -266,7 +268,9 @@ class _CompressedNode extends _TrieNode {
return _FullNode(nodes);
}

@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
int _compressedIndex(int bit) {
return _bitCount(occupiedIndices & (bit - 1));
}
Expand Down Expand Up @@ -351,8 +355,9 @@ class _HashCollisionNode extends _TrieNode {
/// Returns number of bits set in a 32bit integer.
///
/// dart2js safe because we work with 32bit integers.
@pragma('vm:prefer-inline')
@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
int _bitCount(int n) {
assert((n & 0xFFFFFFFF) == n);
n = n - ((n >> 1) & 0x55555555);
Expand All @@ -367,8 +372,9 @@ int _bitCount(int n) {
///
/// Caveat: do not replace with List.of or similar methods. They are
/// considerably slower.
@pragma('vm:prefer-inline')
@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
List<Object?> _copy(List<Object?> array) {
final List<Object?> clone = _makeArray(array.length);
for (int j = 0; j < array.length; j++) {
Expand All @@ -384,17 +390,19 @@ List<Object?> _copy(List<Object?> array) {
/// (growable array instance pointing to a fixed array instance) and
/// consequently fixed length arrays are faster to allocated, require less
/// memory and are faster to access (less indirections).
@pragma('vm:prefer-inline')
@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
List<Object?> _makeArray(int length) {
return List<Object?>.filled(length, null);
}

/// This helper method becomes an no-op when compiled with dart2js on
/// with high level of optimizations enabled.
@pragma('dart2js:tryInline')
@pragma('dart2js:as:trust')
@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
T _unsafeCast<T>(Object? o) {
return o as T;
}
2 changes: 2 additions & 0 deletions packages/flutter/lib/src/rendering/object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,9 @@ abstract class RenderObject with DiagnosticableTreeMixin implements HitTestTarge
/// This is useful when you have to temporarily clear that variable to
/// disable some false-positive checks, such as when computing toStringDeep
/// or using custom trees.
@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
static T _withDebugActiveLayoutCleared<T>(T Function() inner) {
RenderObject? debugPreviousActiveLayout;
assert(() {
Expand Down
8 changes: 8 additions & 0 deletions packages/flutter/lib/src/widgets/framework.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3763,7 +3763,9 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
///
/// See the [RenderObjectElement] documentation for more information on slots.
@protected
@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
Element? updateChild(Element? child, Widget? newWidget, Object? newSlot) {
if (newWidget == null) {
if (child != null) {
Expand Down Expand Up @@ -4285,7 +4287,9 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
/// The element returned by this function will already have been mounted and
/// will be in the "active" lifecycle state.
@protected
@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
Element inflateWidget(Widget newWidget, Object? newSlot) {
final bool isTimelineTracked = !kReleaseMode && _isProfileBuildsEnabledFor(newWidget);
if (isTimelineTracked) {
Expand Down Expand Up @@ -5167,7 +5171,9 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
/// Another example is the [AnimatedBuilder.child] property, which allows the
/// non-animating parts of a subtree to remain static even as the
/// [AnimatedBuilder.builder] callback recreates the other components.
@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
void rebuild({bool force = false}) {
assert(_lifecycleState != _ElementLifecycle.initial);
if (_lifecycleState != _ElementLifecycle.active || (!_dirty && !force)) {
Expand Down Expand Up @@ -6485,7 +6491,9 @@ abstract class RenderObjectElement extends Element {
_performRebuild(); // calls widget.updateRenderObject()
}

@pragma('dart2js:tryInline')
@pragma('vm:prefer-inline')
@pragma('wasm:prefer-inline')
void _performRebuild() {
assert(() {
_debugDoingBuild = true;
Expand Down

0 comments on commit b09ca49

Please sign in to comment.