Merge pre-fill loop into main line loop
There's no need to go through all children before starting the main line loop as we'll visit all children in the former loop anyway. This diff merges the pre-fill loop into the main line one to avoid an extraneous traversal on the node's children.
This commit is contained in:
67
src/Layout.c
67
src/Layout.c
@@ -604,9 +604,39 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
||||
css_node_t* child;
|
||||
css_flex_direction_t axis;
|
||||
|
||||
// Pre-fill some dimensions straight from the parent
|
||||
for (i = 0; i < childCount; ++i) {
|
||||
float definedMainDim = CSS_UNDEFINED;
|
||||
if (isMainDimDefined) {
|
||||
definedMainDim = node->layout.dimensions[dim[mainAxis]] - paddingAndBorderAxisMain;
|
||||
}
|
||||
|
||||
// We want to execute the next two loops one per line with flex-wrap
|
||||
int startLine = 0;
|
||||
int endLine = 0;
|
||||
// int nextOffset = 0;
|
||||
int alreadyComputedNextLayout = 0;
|
||||
// We aggregate the total dimensions of the container in those two variables
|
||||
float linesCrossDim = 0;
|
||||
float linesMainDim = 0;
|
||||
int linesCount = 0;
|
||||
while (endLine < childCount) {
|
||||
// <Loop A> Layout non flexible children and count children by type
|
||||
|
||||
// mainContentDim is accumulation of the dimensions and margin of all the
|
||||
// non flexible children. This will be used in order to either set the
|
||||
// dimensions of the node if none already exist, or to compute the
|
||||
// remaining space left for the flexible children.
|
||||
float mainContentDim = 0;
|
||||
|
||||
// There are three kind of children, non flexible, flexible and absolute.
|
||||
// We need to know how many there are in order to distribute the space.
|
||||
int flexibleChildrenCount = 0;
|
||||
float totalFlexible = 0;
|
||||
int nonFlexibleChildrenCount = 0;
|
||||
|
||||
float maxWidth;
|
||||
for (i = startLine; i < childCount; ++i) {
|
||||
child = node->get_child(node->context, i);
|
||||
|
||||
// Pre-fill cross axis dimensions when the child is using stretch before
|
||||
// we call the recursive layout pass
|
||||
if (getAlignItem(node, child) == CSS_ALIGN_STRETCH &&
|
||||
@@ -640,40 +670,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth, css_direction
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float definedMainDim = CSS_UNDEFINED;
|
||||
if (isMainDimDefined) {
|
||||
definedMainDim = node->layout.dimensions[dim[mainAxis]] - paddingAndBorderAxisMain;
|
||||
}
|
||||
|
||||
// We want to execute the next two loops one per line with flex-wrap
|
||||
int startLine = 0;
|
||||
int endLine = 0;
|
||||
// int nextOffset = 0;
|
||||
int alreadyComputedNextLayout = 0;
|
||||
// We aggregate the total dimensions of the container in those two variables
|
||||
float linesCrossDim = 0;
|
||||
float linesMainDim = 0;
|
||||
int linesCount = 0;
|
||||
while (endLine < childCount) {
|
||||
// <Loop A> Layout non flexible children and count children by type
|
||||
|
||||
// mainContentDim is accumulation of the dimensions and margin of all the
|
||||
// non flexible children. This will be used in order to either set the
|
||||
// dimensions of the node if none already exist, or to compute the
|
||||
// remaining space left for the flexible children.
|
||||
float mainContentDim = 0;
|
||||
|
||||
// There are three kind of children, non flexible, flexible and absolute.
|
||||
// We need to know how many there are in order to distribute the space.
|
||||
int flexibleChildrenCount = 0;
|
||||
float totalFlexible = 0;
|
||||
int nonFlexibleChildrenCount = 0;
|
||||
|
||||
float maxWidth;
|
||||
for (i = startLine; i < childCount; ++i) {
|
||||
child = node->get_child(node->context, i);
|
||||
float nextContentDim = 0;
|
||||
|
||||
// It only makes sense to consider a child flexible if we have a computed
|
||||
|
@@ -472,9 +472,39 @@ var computeLayout = (function() {
|
||||
var/*css_node_t**/ child;
|
||||
var/*(c)!css_flex_direction_t*//*(java)!int*/ axis;
|
||||
|
||||
// Pre-fill some dimensions straight from the parent
|
||||
for (i = 0; i < childCount; ++i) {
|
||||
var/*float*/ definedMainDim = CSS_UNDEFINED;
|
||||
if (isMainDimDefined) {
|
||||
definedMainDim = node.layout[dim[mainAxis]] - paddingAndBorderAxisMain;
|
||||
}
|
||||
|
||||
// We want to execute the next two loops one per line with flex-wrap
|
||||
var/*int*/ startLine = 0;
|
||||
var/*int*/ endLine = 0;
|
||||
// var/*int*/ nextOffset = 0;
|
||||
var/*int*/ alreadyComputedNextLayout = 0;
|
||||
// We aggregate the total dimensions of the container in those two variables
|
||||
var/*float*/ linesCrossDim = 0;
|
||||
var/*float*/ linesMainDim = 0;
|
||||
var/*int*/ linesCount = 0;
|
||||
while (endLine < childCount) {
|
||||
// <Loop A> Layout non flexible children and count children by type
|
||||
|
||||
// mainContentDim is accumulation of the dimensions and margin of all the
|
||||
// non flexible children. This will be used in order to either set the
|
||||
// dimensions of the node if none already exist, or to compute the
|
||||
// remaining space left for the flexible children.
|
||||
var/*float*/ mainContentDim = 0;
|
||||
|
||||
// There are three kind of children, non flexible, flexible and absolute.
|
||||
// We need to know how many there are in order to distribute the space.
|
||||
var/*int*/ flexibleChildrenCount = 0;
|
||||
var/*float*/ totalFlexible = 0;
|
||||
var/*int*/ nonFlexibleChildrenCount = 0;
|
||||
|
||||
var/*float*/ maxWidth;
|
||||
for (i = startLine; i < childCount; ++i) {
|
||||
child = node.children[i];
|
||||
|
||||
// Pre-fill cross axis dimensions when the child is using stretch before
|
||||
// we call the recursive layout pass
|
||||
if (getAlignItem(node, child) === CSS_ALIGN_STRETCH &&
|
||||
@@ -508,40 +538,7 @@ var computeLayout = (function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var/*float*/ definedMainDim = CSS_UNDEFINED;
|
||||
if (isMainDimDefined) {
|
||||
definedMainDim = node.layout[dim[mainAxis]] - paddingAndBorderAxisMain;
|
||||
}
|
||||
|
||||
// We want to execute the next two loops one per line with flex-wrap
|
||||
var/*int*/ startLine = 0;
|
||||
var/*int*/ endLine = 0;
|
||||
// var/*int*/ nextOffset = 0;
|
||||
var/*int*/ alreadyComputedNextLayout = 0;
|
||||
// We aggregate the total dimensions of the container in those two variables
|
||||
var/*float*/ linesCrossDim = 0;
|
||||
var/*float*/ linesMainDim = 0;
|
||||
var/*int*/ linesCount = 0;
|
||||
while (endLine < childCount) {
|
||||
// <Loop A> Layout non flexible children and count children by type
|
||||
|
||||
// mainContentDim is accumulation of the dimensions and margin of all the
|
||||
// non flexible children. This will be used in order to either set the
|
||||
// dimensions of the node if none already exist, or to compute the
|
||||
// remaining space left for the flexible children.
|
||||
var/*float*/ mainContentDim = 0;
|
||||
|
||||
// There are three kind of children, non flexible, flexible and absolute.
|
||||
// We need to know how many there are in order to distribute the space.
|
||||
var/*int*/ flexibleChildrenCount = 0;
|
||||
var/*float*/ totalFlexible = 0;
|
||||
var/*int*/ nonFlexibleChildrenCount = 0;
|
||||
|
||||
var/*float*/ maxWidth;
|
||||
for (i = startLine; i < childCount; ++i) {
|
||||
child = node.children[i];
|
||||
var/*float*/ nextContentDim = 0;
|
||||
|
||||
// It only makes sense to consider a child flexible if we have a computed
|
||||
|
@@ -421,9 +421,39 @@ public class LayoutEngine {
|
||||
CSSNode child;
|
||||
int axis;
|
||||
|
||||
// Pre-fill some dimensions straight from the parent
|
||||
for (i = 0; i < childCount; ++i) {
|
||||
float definedMainDim = CSSConstants.UNDEFINED;
|
||||
if (isMainDimDefined) {
|
||||
definedMainDim = node.layout.dimensions[dim[mainAxis]] - paddingAndBorderAxisMain;
|
||||
}
|
||||
|
||||
// We want to execute the next two loops one per line with flex-wrap
|
||||
int startLine = 0;
|
||||
int endLine = 0;
|
||||
// int nextOffset = 0;
|
||||
int alreadyComputedNextLayout = 0;
|
||||
// We aggregate the total dimensions of the container in those two variables
|
||||
float linesCrossDim = 0;
|
||||
float linesMainDim = 0;
|
||||
int linesCount = 0;
|
||||
while (endLine < childCount) {
|
||||
// <Loop A> Layout non flexible children and count children by type
|
||||
|
||||
// mainContentDim is accumulation of the dimensions and margin of all the
|
||||
// non flexible children. This will be used in order to either set the
|
||||
// dimensions of the node if none already exist, or to compute the
|
||||
// remaining space left for the flexible children.
|
||||
float mainContentDim = 0;
|
||||
|
||||
// There are three kind of children, non flexible, flexible and absolute.
|
||||
// We need to know how many there are in order to distribute the space.
|
||||
int flexibleChildrenCount = 0;
|
||||
float totalFlexible = 0;
|
||||
int nonFlexibleChildrenCount = 0;
|
||||
|
||||
float maxWidth;
|
||||
for (i = startLine; i < childCount; ++i) {
|
||||
child = node.getChildAt(i);
|
||||
|
||||
// Pre-fill cross axis dimensions when the child is using stretch before
|
||||
// we call the recursive layout pass
|
||||
if (getAlignItem(node, child) == CSSAlign.STRETCH &&
|
||||
@@ -457,40 +487,7 @@ public class LayoutEngine {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float definedMainDim = CSSConstants.UNDEFINED;
|
||||
if (isMainDimDefined) {
|
||||
definedMainDim = node.layout.dimensions[dim[mainAxis]] - paddingAndBorderAxisMain;
|
||||
}
|
||||
|
||||
// We want to execute the next two loops one per line with flex-wrap
|
||||
int startLine = 0;
|
||||
int endLine = 0;
|
||||
// int nextOffset = 0;
|
||||
int alreadyComputedNextLayout = 0;
|
||||
// We aggregate the total dimensions of the container in those two variables
|
||||
float linesCrossDim = 0;
|
||||
float linesMainDim = 0;
|
||||
int linesCount = 0;
|
||||
while (endLine < childCount) {
|
||||
// <Loop A> Layout non flexible children and count children by type
|
||||
|
||||
// mainContentDim is accumulation of the dimensions and margin of all the
|
||||
// non flexible children. This will be used in order to either set the
|
||||
// dimensions of the node if none already exist, or to compute the
|
||||
// remaining space left for the flexible children.
|
||||
float mainContentDim = 0;
|
||||
|
||||
// There are three kind of children, non flexible, flexible and absolute.
|
||||
// We need to know how many there are in order to distribute the space.
|
||||
int flexibleChildrenCount = 0;
|
||||
float totalFlexible = 0;
|
||||
int nonFlexibleChildrenCount = 0;
|
||||
|
||||
float maxWidth;
|
||||
for (i = startLine; i < childCount; ++i) {
|
||||
child = node.getChildAt(i);
|
||||
float nextContentDim = 0;
|
||||
|
||||
// It only makes sense to consider a child flexible if we have a computed
|
||||
|
Reference in New Issue
Block a user