From 59bcac32892fcea0b190e50b93ea8754eedfdef6 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Tue, 19 Feb 2019 09:54:48 -0800 Subject: [PATCH] Make node printing private Summary: @public Removes `YGNodeGetPrintFunc`, and encapsulates node printing within `YGNode`. This is necessary for allowing for context-aware callback functions, which will ultimately allow for removal of weak global JNI references. On a side node, the printing logic does not seem to be well thought through: print functions print as a side effect to whatever output they choose. Printing that uses callbacks is printing to different output streams or strings, though. We need to consolidate Yoga debugging, and make it all more stringent. Reviewed By: SidharthGuglani Differential Revision: D14131024 fbshipit-source-id: 68704682dab3e7dfba61930bb03003d7d4723b80 --- yoga/YGNode.cpp | 8 +++++++- yoga/YGNode.h | 4 +--- yoga/YGNodePrint.cpp | 4 +--- yoga/Yoga.cpp | 16 +++------------- yoga/Yoga.h | 1 - 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index 303df5bc..77000b5c 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -12,6 +12,12 @@ using namespace facebook; using facebook::yoga::detail::CompactValue; +void YGNode::print() { + if (print_ != nullptr) { + print_(this); + } +} + YGFloatOptional YGNode::getLeadingPosition( const YGFlexDirection axis, const float axisSize) const { @@ -298,7 +304,7 @@ YGNode& YGNode::operator=(const YGNode& node) { } context_ = node.getContext(); - print_ = node.getPrintFunc(); + print_ = node.print_; hasNewLayout_ = node.getHasNewLayout(); nodeType_ = node.getNodeType(); measureUsesContext_ = node.measureUsesContext_; diff --git a/yoga/YGNode.h b/yoga/YGNode.h index ddb5fa07..14bc6639 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -68,9 +68,7 @@ public: return context_; } - YGPrintFunc getPrintFunc() const { - return print_; - } + void print(); bool getHasNewLayout() const { return hasNewLayout_; diff --git a/yoga/YGNodePrint.cpp b/yoga/YGNodePrint.cpp index 5e51a405..a4db36f2 100644 --- a/yoga/YGNodePrint.cpp +++ b/yoga/YGNodePrint.cpp @@ -114,9 +114,7 @@ void YGNodeToString( uint32_t level) { indent(str, level); appendFormatedString(str, "
getPrintFunc() != nullptr) { - node->getPrintFunc()(node); - } + node->print(); if (options & YGPrintOptionsLayout) { appendFormatedString(str, "layout=\""); diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 98f78e6b..c87f776d 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -169,10 +169,6 @@ void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc) { node->setDirtiedFunc(dirtiedFunc); } -YGPrintFunc YGNodeGetPrintFunc(YGNodeRef node) { - return node->getPrintFunc(); -} - void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) { node->setPrintFunc(printFunc); } @@ -3847,9 +3843,7 @@ bool YGLayoutNodeInternal( "%s%d.{[skipped] ", YGSpacer(gDepth), gDepth); - if (node->getPrintFunc() != nullptr) { - node->getPrintFunc()(node); - } + node->print(); Log::log( node, YGLogLevelVerbose, @@ -3873,9 +3867,7 @@ bool YGLayoutNodeInternal( YGSpacer(gDepth), gDepth, needToVisitNode ? "*" : ""); - if (node->getPrintFunc() != nullptr) { - node->getPrintFunc()(node); - } + node->print(); Log::log( node, YGLogLevelVerbose, @@ -3911,9 +3903,7 @@ bool YGLayoutNodeInternal( YGSpacer(gDepth), gDepth, needToVisitNode ? "*" : ""); - if (node->getPrintFunc() != nullptr) { - node->getPrintFunc()(node); - } + node->print(); Log::log( node, YGLogLevelVerbose, diff --git a/yoga/Yoga.h b/yoga/Yoga.h index 86aa152a..753a2f9f 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -138,7 +138,6 @@ bool YGNodeHasBaselineFunc(YGNodeRef node); void YGNodeSetBaselineFunc(YGNodeRef node, YGBaselineFunc baselineFunc); YGDirtiedFunc YGNodeGetDirtiedFunc(YGNodeRef node); void YGNodeSetDirtiedFunc(YGNodeRef node, YGDirtiedFunc dirtiedFunc); -YGPrintFunc YGNodeGetPrintFunc(YGNodeRef node); void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc); WIN_EXPORT bool YGNodeGetHasNewLayout(YGNodeRef node); WIN_EXPORT void YGNodeSetHasNewLayout(YGNodeRef node, bool hasNewLayout);