a more effective implementation of Pane::LayoutSizeNode::operator= #16161

Open
opened 2026-01-31 04:59:24 +00:00 by claunia · 0 comments
Owner

Originally created by @ltimaginea on GitHub (Dec 16, 2021).

fb597ed304/src/cascadia/TerminalApp/Pane.LayoutSizeNode.cpp (L35-L46)

Actually, we don't need Pane::LayoutSizeNode::_AssignChildNode to help define Pane::LayoutSizeNode::operator= . It makes things more complicated. Like LayoutSizeNode's copy constructor, LayoutSizeNode's copy assignment operator can be defined more effectively as follows:

Pane::LayoutSizeNode& Pane::LayoutSizeNode::operator=(const LayoutSizeNode& other)
{
	size = other.size;
	isMinimumSize = other.isMinimumSize;

	firstChild = other.firstChild ? std::make_unique<LayoutSizeNode>(*other.firstChild) : nullptr;
	secondChild = other.secondChild ? std::make_unique<LayoutSizeNode>(*other.secondChild) : nullptr;
	nextFirstChild = other.nextFirstChild ? std::make_unique<LayoutSizeNode>(*other.nextFirstChild) : nullptr;
	nextSecondChild = other.nextSecondChild ? std::make_unique<LayoutSizeNode>(*other.nextSecondChild) : nullptr;

	return *this;
}
Originally created by @ltimaginea on GitHub (Dec 16, 2021). https://github.com/microsoft/terminal/blob/fb597ed304ec6eef245405c9652e9b8a029b821f/src/cascadia/TerminalApp/Pane.LayoutSizeNode.cpp#L35-L46 Actually, we don't need `Pane::LayoutSizeNode::_AssignChildNode` to help define `Pane::LayoutSizeNode::operator=` . It makes things more complicated. Like LayoutSizeNode's copy constructor, LayoutSizeNode's copy assignment operator can be defined more effectively as follows: ```cpp Pane::LayoutSizeNode& Pane::LayoutSizeNode::operator=(const LayoutSizeNode& other) { size = other.size; isMinimumSize = other.isMinimumSize; firstChild = other.firstChild ? std::make_unique<LayoutSizeNode>(*other.firstChild) : nullptr; secondChild = other.secondChild ? std::make_unique<LayoutSizeNode>(*other.secondChild) : nullptr; nextFirstChild = other.nextFirstChild ? std::make_unique<LayoutSizeNode>(*other.nextFirstChild) : nullptr; nextSecondChild = other.nextSecondChild ? std::make_unique<LayoutSizeNode>(*other.nextSecondChild) : nullptr; return *this; } ```
claunia added the Help WantedIssue-TaskIn-PRProduct-TerminalArea-CodeHealth labels 2026-01-31 04:59:25 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16161