Skip to content

Commit

Permalink
Use the injected treeProps for Layout PerfEvent (#574)
Browse files Browse the repository at this point in the history
Summary:
At the runtime, the ComponentContext's treeProps could be null. In this case, it would better to use the treeProps that provided by caller.
Pull Request resolved: #574

Reviewed By: astreet

Differential Revision: D16599130

Pulled By: colriot

fbshipit-source-id: b24fb0242b0d0878886232d3543c1ae7c80208eb
  • Loading branch information
boduan-coder authored and facebook-github-bot committed Aug 14, 2019
1 parent 6a58557 commit d228f8a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,10 @@ private void calculateLayout(
final PerfEvent layoutEvent =
logger != null
? LogTreePopulator.populatePerfEventFromLogger(
mContext, logger, logger.newPerformanceEvent(mContext, EVENT_LAYOUT_CALCULATE))
mContext,
treeProps,
logger,
logger.newPerformanceEvent(mContext, EVENT_LAYOUT_CALCULATE))
: null;

if (layoutEvent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ private LogTreePopulator() {}
@CheckReturnValue
public static PerfEvent populatePerfEventFromLogger(
ComponentContext c, ComponentsLogger logger, @Nullable PerfEvent perfEvent) {
return populatePerfEventFromLogger(c, c.getTreeProps(), logger, perfEvent);
}

/**
* Annotate a log event with the log tag set in the context, and convert the treeprops into perf
* event annotations using a {@link ComponentsLogger} implementation.
*
* @return Annotated perf event, or <code>null</code> if the resulting event isn't deemed worthy
* of reporting.
*/
@Nullable
@CheckReturnValue
public static PerfEvent populatePerfEventFromLogger(
ComponentContext c,
@Nullable TreeProps treeProps,
ComponentsLogger logger,
@Nullable PerfEvent perfEvent) {
if (perfEvent == null) {
return null;
}
Expand All @@ -50,7 +67,6 @@ public static PerfEvent populatePerfEventFromLogger(

perfEvent.markerAnnotate(FrameworkLogEvents.PARAM_LOG_TAG, logTag);

@Nullable final TreeProps treeProps = c.getTreeProps();
if (treeProps == null) {
return perfEvent;
}
Expand Down

0 comments on commit d228f8a

Please sign in to comment.