Extract duplicated keyframe-setup helpers in LayoutAnimationKeyFrameManager::pullTransaction (#57156)#57156
Open
sammy-SC wants to merge 7 commits into
Open
Extract duplicated keyframe-setup helpers in LayoutAnimationKeyFrameManager::pullTransaction (#57156)#57156sammy-SC wants to merge 7 commits into
LayoutAnimationKeyFrameManager::pullTransaction (#57156)#57156sammy-SC wants to merge 7 commits into
Conversation
Summary: `BaseTextProps::appendTextAttributesProps` builds a `folly::dynamic` diff of ~29 text attributes through a long flat sequence of per-attribute `if (changed) result[key] = ...` blocks, many with an embedded `has_value() ? convert(...) : nullptr` ternary. That gave the function a cyclomatic complexity (CCN) of 47, well into the "complex, hard to test" range. This is a pure, behavior-preserving refactor. The four recurring compare-and-assign shapes — plain `!=`, `floatEquality`, optional-with-converter, and color dereference — are pulled into small file-local `static` helpers, and the function body becomes a flat list of helper calls in the exact same order, with the exact same keys, conversions, and values. The serialized output (including `folly::dynamic` insertion order) is identical. Only the `.cpp` is touched; there are no public header or API changes. Changelog: [Internal] Differential Revision: D108027815
Summary: `AndroidTextInputProps::getDiffProps` computes a `folly::dynamic` prop diff through ~57 sequential per-prop `if (field != oldProps->field) result[key] = ...` blocks (plus a nested `has_value()` branch for `textAlignVertical` and an optional ternary for `acceptDragAndDropTypes`), giving the function a cyclomatic complexity (CCN) of 63 — past the landing threshold. This is a pure, behavior-preserving refactor. The recurring compare-and-assign shapes — plain `!=`, color dereference, `floatEquality`, direct `toString`/`toDynamic` conversion, and optional-with-converter — are pulled into small file-local `static` helpers, and the body becomes a flat list of helper calls in the exact same order, with the same keys, comparisons (`!=` vs `floatEquality`), conversions, and values. The serialized output (including `folly::dynamic` insertion order, so the duplicate `numberOfLines`/`includeFontPadding` keys still resolve identically) is unchanged. Only the `.cpp` is touched; there are no public header or API changes. Changelog: [Internal] Differential Revision: D108027818
Summary: `HostPlatformViewProps::getDiffProps` computes a `folly::dynamic` prop diff for Android with the highest complexity in the file: ~60 sequential per-prop `if (field != oldProps->field) result[key] = ...` guards plus inline `switch`es (`outlineStyle`, `backfaceVisibility`), a 28-call events block, a transform loop, and several accessibility object/array builders, for a cyclomatic complexity (CCN) of 87. This is a pure, behavior-preserving refactor. The recurring compare-and-assign shapes — plain `!=`, color dereference, direct `toString`/`toDynamic` conversion, and optional-with-converter — are pulled into small file-local `static` helpers, and the genuinely branching blocks (the two enum `switch`es, `overflow`/`scroll`, the events block, the transform loop, and the accessibility state/labelledBy/order/value/actions builders) are each moved verbatim into a named helper. Every prop keeps its explicit key/value/conversion on one line and in the same order, so the serialized `folly::dynamic` (keys, values, insertion order) is identical. The `// Borders` block is left inline unchanged. Only the `.cpp` is touched; there are no public header or API changes. Changelog: [Internal] Differential Revision: D108027816
Summary: `calculateShadowViewMutationsFlattener` (CCN 73) and `calculateShadowViewMutations` (CCN 45) are the core of the Fabric tree differ and were the two most complex functions in the mounting library. This is a pure, behavior-preserving refactor: cohesive blocks are extracted into file-local `static` helpers (remove/insert-on-(un)flatten, matched-grandchildren update, opposite/normal reparent handling, and the greedy diff stages), turning both functions into flat sequences of helper calls. Traversal order and the exact sequence of emitted mutations are preserved. Only the `.cpp` is touched; no header or public API change. Changelog: [Internal] Differential Revision: D108027813
Summary: `FabricMountingManager::executeMount` (CCN 59) dispatched a large per-mutation-type `switch` with repeated buffer-append boilerplate. This is a pure, behavior-preserving refactor: the five mutation-type case bodies are extracted into file-local `static` helpers backed by a small `MountItemBuffers` struct (holding `maintainMutationOrder` plus references to the output vectors, with an `orderedOr()` helper reproducing the exact `maintainMutationOrder ? common : bucket` selection), and the seven repeated empty-guard + per-item loops collapse into one templated batch writer. Ordering and side effects are preserved exactly (including the Update-case event-emitter quirk and Delete-batch-last ordering). Anonymous-namespace helpers only; no header or public API change. Changelog: [Internal] Differential Revision: D108027810
Summary: `UIManagerBinding::get` (CCN 71) builds the UIManager JSI host object via one long chain of `if (methodName == "...") return Function::createFromHostFunction(...)`. This is a pure, behavior-preserving refactor: contiguous groups of methods are extracted into file-local `static` helpers that each return `std::optional<jsi::Value>` (node management, child set, layout/command, measurement, DOM-compat, view-transition, etc.); `get` consults them in order and falls through identically. Method names, arities, and host-function bodies are unchanged. Only the `.cpp` is touched; no header or public API change. Changelog: [Internal] Differential Revision: D108027814
…Manager::pullTransaction` (facebook#57156) Summary: `LayoutAnimationKeyFrameManager::pullTransaction` (CCN 151) is the single most complex function in ReactCommon. As a first, conservative, behavior-preserving pass, this extracts file-local `static` helpers for the parts that are safe to factor out: the two duplicated opacity/scale prop-setup blocks (the INSERT/Create path on `viewStart` and the REMOVE/Delete path on `viewFinal`, collapsed to one helper each), the insert/delete/reparent tag pre-pass, and the conflicting-keyframe re-queue logic. Behavior is unchanged. This is a partial reduction (CCN 151 -> 102): the function is still above threshold. The remaining bulk is the per-mutation keyframe-build loop and the two large post-processing branches, which call protected members of the class — file-local statics cannot reach those, and lowering them further requires adding private methods (a header change). That is deferred to a follow-up. Changelog: [Internal] Differential Revision: D108027812
baa60b8 to
2dc4e99
Compare
LayoutAnimationKeyFrameManager::pullTransactionLayoutAnimationKeyFrameManager::pullTransaction (#57156)
|
@sammy-SC has exported this pull request. If you are a Meta employee, you can view the originating Diff in D108027812. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
LayoutAnimationKeyFrameManager::pullTransaction(CCN 151) is the single most complex function in ReactCommon. As a first, conservative, behavior-preserving pass, this extracts file-localstatichelpers for the parts that are safe to factor out: the two duplicated opacity/scale prop-setup blocks (the INSERT/Create path onviewStartand the REMOVE/Delete path onviewFinal, collapsed to one helper each), the insert/delete/reparent tag pre-pass, and the conflicting-keyframe re-queue logic. Behavior is unchanged.This is a partial reduction (CCN 151 -> 102): the function is still above threshold. The remaining bulk is the per-mutation keyframe-build loop and the two large post-processing branches, which call protected members of the class — file-local statics cannot reach those, and lowering them further requires adding private methods (a header change). That is deferred to a follow-up.
Changelog: [Internal]
Differential Revision: D108027812