computeFirstAnimatingVisibleIndex method

int computeFirstAnimatingVisibleIndex()

Returns the smallest _visibleOrder index among all currently-animating nodes, or visibleNodeCount when none are visible / none are animating.

Used by the render object to skip the O(N) Pass 1 offset rescan during animation: everything before the returned index has stable offset and extent from the prior frame, so only indices >= firstAnimatingIndex need to be recomputed.

Complexity is O(A) in the number of animating nodes, which is normally much smaller than the visible-order length.

Implementation

int computeFirstAnimatingVisibleIndex() {
  if (!hasActiveAnimations) return _order.length;
  // Cache key combines animation generation with structure generation:
  // the result depends on which keys are animating AND their visible indices.
  final sig = _animationGeneration ^ (_structureGeneration * 2654435761);
  if (sig == _firstAnimatingIndexCacheSig &&
      _firstAnimatingIndexCacheVal <= _order.length) {
    return _firstAnimatingIndexCacheVal;
  }
  // Force the mirror rebuild so `_writtenAnimatingNids` reflects the
  // current generation. The discarded return value is intentional —
  // we only need the side effect of populating the sparse-tracked list.
  _ensureAnimatingKeys();
  int min = _order.length;
  final indexByNid = _order.indexByNid;
  for (final nid in _writtenAnimatingNids) {
    final idx = indexByNid[nid];
    if (idx != VisibleOrderBuffer.kNotVisible && idx < min) {
      min = idx;
    }
  }
  _firstAnimatingIndexCacheSig = sig;
  _firstAnimatingIndexCacheVal = min;
  return min;
}