Skip to content

Commit

Permalink
Remove YGNodeSetPrintFunc and related
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#42274

Separate from `YGConfigSetPrintTreeFlag` we have a public API `YGNodeSetPrintFunc` which sets a function called, if you manually change a constant in source code during debugging.

This is not debug-only, is exposed as part of the public API (without a way to turn it on from the public API), and takes up a pointer per node doing nothing.

I'm not aware of anyone recently using the capability, and the tracing/event related work done since then would be more powerful for this anyway.

Remove the API.

Differential Revision: D52767445
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Jan 14, 2024
1 parent 508df05 commit 70a218f
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 121 deletions.
4 changes: 0 additions & 4 deletions yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,6 @@ YGNodeType YGNodeGetNodeType(YGNodeConstRef node) {
return unscopedEnum(resolveRef(node)->getNodeType());
}

void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc) {
resolveRef(node)->setPrintFunc(printFunc);
}

void YGNodeSetAlwaysFormsContainingBlock(
YGNodeRef node,
bool alwaysFormsContainingBlock) {
Expand Down
8 changes: 0 additions & 8 deletions yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,6 @@ YG_EXPORT void YGNodeSetNodeType(YGNodeRef node, YGNodeType nodeType);
*/
YG_EXPORT YGNodeType YGNodeGetNodeType(YGNodeConstRef node);

typedef void (*YGPrintFunc)(YGNodeConstRef node);

/**
* Set a function to be called when configured to print nodes during layout for
* debugging.
*/
YG_EXPORT void YGNodeSetPrintFunc(YGNodeRef node, YGPrintFunc printFunc);

/**
* Make it so that this node will always form a containing block for any
* descendant nodes. This is useful for when a node has a property outside of
Expand Down
93 changes: 0 additions & 93 deletions yoga/algorithm/CalculateLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,35 +2097,6 @@ static void calculateLayoutImpl(
}
}

bool gPrintChanges = false;
bool gPrintSkips = false;

static const char* spacer =
" ";

static const char* spacerWithLength(const unsigned long level) {
const size_t spacerLen = strlen(spacer);
if (level > spacerLen) {
return &spacer[0];
} else {
return &spacer[spacerLen - level];
}
}

static const char* sizingModeName(
const SizingMode mode,
const bool performLayout) {
switch (mode) {
case SizingMode::MaxContent:
return performLayout ? "LAY_UNDEFINED" : "UNDEFINED";
case SizingMode::StretchFit:
return performLayout ? "LAY_EXACTLY" : "EXACTLY";
case SizingMode::FitContent:
return performLayout ? "LAY_AT_MOST" : "AT_MOST";
}
return "";
}

//
// This is a wrapper around the calculateLayoutImpl function. It determines
// whether the layout request is redundant and can be skipped.
Expand Down Expand Up @@ -2252,48 +2223,7 @@ bool calculateLayoutInternal(

(performLayout ? layoutMarkerData.cachedLayouts
: layoutMarkerData.cachedMeasures) += 1;

if (gPrintChanges && gPrintSkips) {
yoga::log(
node,
LogLevel::Verbose,
"%s%d.{[skipped] ",
spacerWithLength(depth),
depth);
node->print();
yoga::log(
node,
LogLevel::Verbose,
"wm: %s, hm: %s, aw: %f ah: %f => d: (%f, %f) %s\n",
sizingModeName(widthSizingMode, performLayout),
sizingModeName(heightSizingMode, performLayout),
availableWidth,
availableHeight,
cachedResults->computedWidth,
cachedResults->computedHeight,
LayoutPassReasonToString(reason));
}
} else {
if (gPrintChanges) {
yoga::log(
node,
LogLevel::Verbose,
"%s%d.{%s",
spacerWithLength(depth),
depth,
needToVisitNode ? "*" : "");
node->print();
yoga::log(
node,
LogLevel::Verbose,
"wm: %s, hm: %s, aw: %f ah: %f %s\n",
sizingModeName(widthSizingMode, performLayout),
sizingModeName(heightSizingMode, performLayout),
availableWidth,
availableHeight,
LayoutPassReasonToString(reason));
}

calculateLayoutImpl(
node,
availableWidth,
Expand All @@ -2309,26 +2239,6 @@ bool calculateLayoutInternal(
generationCount,
reason);

if (gPrintChanges) {
yoga::log(
node,
LogLevel::Verbose,
"%s%d.}%s",
spacerWithLength(depth),
depth,
needToVisitNode ? "*" : "");
node->print();
yoga::log(
node,
LogLevel::Verbose,
"wm: %s, hm: %s, d: (%f, %f) %s\n",
sizingModeName(widthSizingMode, performLayout),
sizingModeName(heightSizingMode, performLayout),
layout->measuredDimension(Dimension::Width),
layout->measuredDimension(Dimension::Height),
LayoutPassReasonToString(reason));
}

layout->lastOwnerDirection = ownerDirection;

if (cachedResults == nullptr) {
Expand All @@ -2338,9 +2248,6 @@ bool calculateLayoutInternal(

if (layout->nextCachedMeasurementsIndex ==
LayoutResults::MaxCachedMeasurements) {
if (gPrintChanges) {
yoga::log(node, LogLevel::Verbose, "Out of cache entries!\n");
}
layout->nextCachedMeasurementsIndex = 0;
}

Expand Down
7 changes: 0 additions & 7 deletions yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Node::Node(Node&& node) {
context_ = node.context_;
measureFunc_ = node.measureFunc_;
baselineFunc_ = node.baselineFunc_;
printFunc_ = node.printFunc_;
dirtiedFunc_ = node.dirtiedFunc_;
style_ = node.style_;
layout_ = node.layout_;
Expand All @@ -49,12 +48,6 @@ Node::Node(Node&& node) {
}
}

void Node::print() {
if (printFunc_ != nullptr) {
printFunc_(this);
}
}

// TODO: Edge value resolution should be moved to `yoga::Style`
template <auto Field>
Style::Length Node::computeEdgeValueForRow(Edge rowEdge, Edge edge) const {
Expand Down
11 changes: 2 additions & 9 deletions yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class YG_EXPORT Node : public ::YGNode {
return alwaysFormsContainingBlock_;
}

void print();

bool getHasNewLayout() const {
return hasNewLayout_;
}
Expand Down Expand Up @@ -250,10 +248,6 @@ class YG_EXPORT Node : public ::YGNode {
alwaysFormsContainingBlock_ = alwaysFormsContainingBlock;
}

void setPrintFunc(YGPrintFunc printFunc) {
printFunc_ = printFunc;
}

void setHasNewLayout(bool hasNewLayout) {
hasNewLayout_ = hasNewLayout;
}
Expand Down Expand Up @@ -376,9 +370,8 @@ class YG_EXPORT Node : public ::YGNode {
bool alwaysFormsContainingBlock_ : 1 = false;
NodeType nodeType_ : bitCount<NodeType>() = NodeType::Default;
void* context_ = nullptr;
YGMeasureFunc measureFunc_ = {nullptr};
YGBaselineFunc baselineFunc_ = {nullptr};
YGPrintFunc printFunc_ = {nullptr};
YGMeasureFunc measureFunc_ = nullptr;
YGBaselineFunc baselineFunc_ = nullptr;
YGDirtiedFunc dirtiedFunc_ = nullptr;
Style style_ = {};
LayoutResults layout_ = {};
Expand Down

0 comments on commit 70a218f

Please sign in to comment.