Skip to content

Simplify BaseTextProps::appendTextAttributesProps (#57150)#57150

Open
sammy-SC wants to merge 1 commit into
react:mainfrom
sammy-SC:export-D108027815
Open

Simplify BaseTextProps::appendTextAttributesProps (#57150)#57150
sammy-SC wants to merge 1 commit into
react:mainfrom
sammy-SC:export-D108027815

Conversation

@sammy-SC

@sammy-SC sammy-SC commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 9, 2026
@facebook-github-tools facebook-github-tools Bot added p: Facebook Partner: Facebook Partner labels Jun 9, 2026
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
@sammy-SC sammy-SC force-pushed the export-D108027815 branch from b81da72 to 38ca607 Compare June 9, 2026 16:11
@meta-codesync meta-codesync Bot changed the title Simplify BaseTextProps::appendTextAttributesProps Simplify BaseTextProps::appendTextAttributesProps (#57150) Jun 9, 2026
@meta-codesync

meta-codesync Bot commented Jun 9, 2026

Copy link
Copy Markdown

@sammy-SC has exported this pull request. If you are a Meta employee, you can view the originating Diff in D108027815.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant