measure function called multi times unnecessarily #334

Closed
opened 2017-01-11 19:11:33 -08:00 by dolmens · 1 comment
dolmens commented 2017-01-11 19:11:33 -08:00 (Migrated from github.com)

the measure function:

static YGSize _measure(YGNodeRef node,
                       float width,
                       YGMeasureMode widthMode,
                       float height,
                       YGMeasureMode heightMode) {
  printf("_measure: %f(%s), %f(%s)\n",
         width,
         (widthMode==YGMeasureModeAtMost?"AtMost":widthMode==YGMeasureModeExactly?"Exactly":"Undefined"),
         height,
         (heightMode==YGMeasureModeAtMost?"AtMost":heightMode==YGMeasureModeExactly?"Exactly":"Undefined"));
  return YGSize {
    .width = 84.f,
    .height = 49.f,
  };
}

the tree:

 YGNodeRef root = YGNodeNew();
  YGNodeStyleSetWidth(root, 288.f);
  YGNodeStyleSetHeight(root, 288.f);
  YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow);
  
  YGNodeRef root_child0 = YGNodeNew();
  YGNodeStyleSetPadding(root_child0, YGEdgeAll, 2.88f);
  YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
  YGNodeInsertChild(root, root_child0, 0);
  
  YGNodeRef root_child0_child0 = YGNodeNew();
  YGNodeSetMeasureFunc(root_child0_child0, _measure);
  YGNodeInsertChild(root_child0, root_child0_child0, 0);
  
  YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
  
  YGNodeFreeRecursive(root);

and the result:

 _measure: 282.239990(AtMost), 282.239990(Exactly)
_measure: 83.999992(AtMost), 282.239990(Exactly)

I test this in iPhone and android mobiles.

Apparently, the float value 83.99999 and 84.f are equal, so the second call is unnecessary, I guess.

the measure function: ``` static YGSize _measure(YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode) { printf("_measure: %f(%s), %f(%s)\n", width, (widthMode==YGMeasureModeAtMost?"AtMost":widthMode==YGMeasureModeExactly?"Exactly":"Undefined"), height, (heightMode==YGMeasureModeAtMost?"AtMost":heightMode==YGMeasureModeExactly?"Exactly":"Undefined")); return YGSize { .width = 84.f, .height = 49.f, }; } ``` the tree: ``` YGNodeRef root = YGNodeNew(); YGNodeStyleSetWidth(root, 288.f); YGNodeStyleSetHeight(root, 288.f); YGNodeStyleSetFlexDirection(root, YGFlexDirectionRow); YGNodeRef root_child0 = YGNodeNew(); YGNodeStyleSetPadding(root_child0, YGEdgeAll, 2.88f); YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow); YGNodeInsertChild(root, root_child0, 0); YGNodeRef root_child0_child0 = YGNodeNew(); YGNodeSetMeasureFunc(root_child0_child0, _measure); YGNodeInsertChild(root_child0, root_child0_child0, 0); YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); YGNodeFreeRecursive(root); ``` and the result: ``` _measure: 282.239990(AtMost), 282.239990(Exactly) _measure: 83.999992(AtMost), 282.239990(Exactly) ``` I test this in iPhone and android mobiles. Apparently, the float value `83.99999` and `84.f` are equal, so the second call is unnecessary, I guess.
emilsjolander commented 2017-01-12 02:17:19 -08:00 (Migrated from github.com)

Good catch, i'll look into it. thanks!

Good catch, i'll look into it. thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#334
No description provided.