Skip to content

Commit b09ca49

Browse files
authored
Use inlining annotations on important methods for all targets (#143923)
1 parent 44e440a commit b09ca49

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

packages/flutter/lib/src/foundation/persistent_hash_map.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ abstract class _TrieNode {
6565
static const int hashBitsPerLevel = 5;
6666
static const int hashBitsPerLevelMask = (1 << hashBitsPerLevel) - 1;
6767

68+
@pragma('dart2js:tryInline')
6869
@pragma('vm:prefer-inline')
70+
@pragma('wasm:prefer-inline')
6971
static int trieIndex(int hash, int bitIndex) {
7072
return (hash >>> bitIndex) & hashBitsPerLevelMask;
7173
}
@@ -266,7 +268,9 @@ class _CompressedNode extends _TrieNode {
266268
return _FullNode(nodes);
267269
}
268270

271+
@pragma('dart2js:tryInline')
269272
@pragma('vm:prefer-inline')
273+
@pragma('wasm:prefer-inline')
270274
int _compressedIndex(int bit) {
271275
return _bitCount(occupiedIndices & (bit - 1));
272276
}
@@ -351,8 +355,9 @@ class _HashCollisionNode extends _TrieNode {
351355
/// Returns number of bits set in a 32bit integer.
352356
///
353357
/// dart2js safe because we work with 32bit integers.
354-
@pragma('vm:prefer-inline')
355358
@pragma('dart2js:tryInline')
359+
@pragma('vm:prefer-inline')
360+
@pragma('wasm:prefer-inline')
356361
int _bitCount(int n) {
357362
assert((n & 0xFFFFFFFF) == n);
358363
n = n - ((n >> 1) & 0x55555555);
@@ -367,8 +372,9 @@ int _bitCount(int n) {
367372
///
368373
/// Caveat: do not replace with List.of or similar methods. They are
369374
/// considerably slower.
370-
@pragma('vm:prefer-inline')
371375
@pragma('dart2js:tryInline')
376+
@pragma('vm:prefer-inline')
377+
@pragma('wasm:prefer-inline')
372378
List<Object?> _copy(List<Object?> array) {
373379
final List<Object?> clone = _makeArray(array.length);
374380
for (int j = 0; j < array.length; j++) {
@@ -384,17 +390,19 @@ List<Object?> _copy(List<Object?> array) {
384390
/// (growable array instance pointing to a fixed array instance) and
385391
/// consequently fixed length arrays are faster to allocated, require less
386392
/// memory and are faster to access (less indirections).
387-
@pragma('vm:prefer-inline')
388393
@pragma('dart2js:tryInline')
394+
@pragma('vm:prefer-inline')
395+
@pragma('wasm:prefer-inline')
389396
List<Object?> _makeArray(int length) {
390397
return List<Object?>.filled(length, null);
391398
}
392399

393400
/// This helper method becomes an no-op when compiled with dart2js on
394401
/// with high level of optimizations enabled.
395-
@pragma('dart2js:tryInline')
396402
@pragma('dart2js:as:trust')
403+
@pragma('dart2js:tryInline')
397404
@pragma('vm:prefer-inline')
405+
@pragma('wasm:prefer-inline')
398406
T _unsafeCast<T>(Object? o) {
399407
return o as T;
400408
}

packages/flutter/lib/src/rendering/object.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,9 @@ abstract class RenderObject with DiagnosticableTreeMixin implements HitTestTarge
19251925
/// This is useful when you have to temporarily clear that variable to
19261926
/// disable some false-positive checks, such as when computing toStringDeep
19271927
/// or using custom trees.
1928+
@pragma('dart2js:tryInline')
19281929
@pragma('vm:prefer-inline')
1930+
@pragma('wasm:prefer-inline')
19291931
static T _withDebugActiveLayoutCleared<T>(T Function() inner) {
19301932
RenderObject? debugPreviousActiveLayout;
19311933
assert(() {

packages/flutter/lib/src/widgets/framework.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3763,7 +3763,9 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
37633763
///
37643764
/// See the [RenderObjectElement] documentation for more information on slots.
37653765
@protected
3766+
@pragma('dart2js:tryInline')
37663767
@pragma('vm:prefer-inline')
3768+
@pragma('wasm:prefer-inline')
37673769
Element? updateChild(Element? child, Widget? newWidget, Object? newSlot) {
37683770
if (newWidget == null) {
37693771
if (child != null) {
@@ -4285,7 +4287,9 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
42854287
/// The element returned by this function will already have been mounted and
42864288
/// will be in the "active" lifecycle state.
42874289
@protected
4290+
@pragma('dart2js:tryInline')
42884291
@pragma('vm:prefer-inline')
4292+
@pragma('wasm:prefer-inline')
42894293
Element inflateWidget(Widget newWidget, Object? newSlot) {
42904294
final bool isTimelineTracked = !kReleaseMode && _isProfileBuildsEnabledFor(newWidget);
42914295
if (isTimelineTracked) {
@@ -5167,7 +5171,9 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
51675171
/// Another example is the [AnimatedBuilder.child] property, which allows the
51685172
/// non-animating parts of a subtree to remain static even as the
51695173
/// [AnimatedBuilder.builder] callback recreates the other components.
5174+
@pragma('dart2js:tryInline')
51705175
@pragma('vm:prefer-inline')
5176+
@pragma('wasm:prefer-inline')
51715177
void rebuild({bool force = false}) {
51725178
assert(_lifecycleState != _ElementLifecycle.initial);
51735179
if (_lifecycleState != _ElementLifecycle.active || (!_dirty && !force)) {
@@ -6485,7 +6491,9 @@ abstract class RenderObjectElement extends Element {
64856491
_performRebuild(); // calls widget.updateRenderObject()
64866492
}
64876493

6494+
@pragma('dart2js:tryInline')
64886495
@pragma('vm:prefer-inline')
6496+
@pragma('wasm:prefer-inline')
64896497
void _performRebuild() {
64906498
assert(() {
64916499
_debugDoingBuild = true;

0 commit comments

Comments
 (0)