Deleted YGSetMemoryFucs as it is unused

Summary: Removed YGSetMemoryFuncs, as it is not used internally and barely externally.

Reviewed By: emilsjolander

Differential Revision: D6374147

fbshipit-source-id: 8c896dce23571268a1a52df5cc72486af9d66df7
This commit is contained in:
Pritesh Nandgaonkar
2017-11-21 03:31:17 -08:00
committed by Facebook Github Bot
parent 5b0dfa471f
commit d98e5aef97
4 changed files with 7 additions and 130 deletions

View File

@@ -52,7 +52,7 @@ typedef enum YGFlexDirection {
YGFlexDirectionRowReverse, YGFlexDirectionRowReverse,
} YGFlexDirection; } YGFlexDirection;
void YGNodeStyleSetFlexDirection(YGNodeRef node, void YGNodeStyleSetFlexDirection(YGNodeRef node,
YGFlexDirection flexDirection); YGFlexDirection flexDirection);
YGFlexDirection YGNodeStyleGetFlexDirection(YGNodeRef node); YGFlexDirection YGNodeStyleGetFlexDirection(YGNodeRef node);
@@ -64,7 +64,7 @@ typedef enum YGJustify {
YGJustifySpaceAround, YGJustifySpaceAround,
} YGJustify; } YGJustify;
void YGNodeStyleSetJustifyContent(YGNodeRef node, void YGNodeStyleSetJustifyContent(YGNodeRef node,
YGJustify justifyContent); YGJustify justifyContent);
YGJustify YGNodeStyleGetJustifyContent(YGNodeRef node); YGJustify YGNodeStyleGetJustifyContent(YGNodeRef node);
@@ -90,7 +90,7 @@ typedef enum YGPositionType {
YGPositionTypeAbsolute, YGPositionTypeAbsolute,
} YGPositionType; } YGPositionType;
void YGNodeStyleSetPositionType(YGNodeRef node, void YGNodeStyleSetPositionType(YGNodeRef node,
YGPositionType positionType); YGPositionType positionType);
YGPositionType YGNodeStyleGetPositionType(YGNodeRef node); YGPositionType YGNodeStyleGetPositionType(YGNodeRef node);
@@ -173,9 +173,9 @@ float YGNodeStyleGetAspectRatio(YGNodeRef node);
Once you have set up a tree of nodes with styles you will want to get the result of a layout calculation. Call `YGNodeCalculateLayout` with the desired width and height or `YGUndefined` to perform the layout calculation. Once this function returns the results of the layout calculation is stored on each node. Traverse the tree and retrieve the values from each node. Once you have set up a tree of nodes with styles you will want to get the result of a layout calculation. Call `YGNodeCalculateLayout` with the desired width and height or `YGUndefined` to perform the layout calculation. Once this function returns the results of the layout calculation is stored on each node. Traverse the tree and retrieve the values from each node.
```c ```c
void YGNodeCalculateLayout(YGNodeRef node, void YGNodeCalculateLayout(YGNodeRef node,
float availableWidth, float availableWidth,
float availableHeight, float availableHeight,
YGDirection parentDirection); YGDirection parentDirection);
float YGNodeLayoutGetLeft(YGNodeRef node); float YGNodeLayoutGetLeft(YGNodeRef node);
float YGNodeLayoutGetTop(YGNodeRef node); float YGNodeLayoutGetTop(YGNodeRef node);
@@ -255,27 +255,11 @@ typedef enum YGExperimentalFeature {
// Current experiments // Current experiments
} YGExperimentalFeature; } YGExperimentalFeature;
void YGSetExperimentalFeatureEnabled(YGExperimentalFeature feature, void YGSetExperimentalFeatureEnabled(YGExperimentalFeature feature,
bool enabled); bool enabled);
bool YGIsExperimentalFeatureEnabled(YGExperimentalFeature feature); bool YGIsExperimentalFeatureEnabled(YGExperimentalFeature feature);
``` ```
### Custom allocators
You may want to swap out the allocator used in Yoga. These functions allow that.
```c
typedef void *(*YGMalloc)(size_t size);
typedef void *(*YGCalloc)(size_t count, size_t size);
typedef void *(*YGRealloc)(void *ptr, size_t size);
typedef void (*YGFree)(void *ptr);
void YGSetMemoryFuncs(YGMalloc cssMalloc,
YGCalloc cssCalloc,
YGRealloc cssRealloc,
YGFree cssFree);
```
### Printing ### Printing
Yoga has some hooks to print debug information while calculating layout. With the printing APIs you can add additional information to a node when it is printed. Yoga has some hooks to print debug information while calculating layout. With the printing APIs you can add additional information to a node when it is printed.

View File

@@ -1,84 +0,0 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include <gtest/gtest.h>
#include <yoga/Yoga.h>
extern int32_t gNodeInstanceCount;
extern int32_t gConfigInstanceCount;
static int testMallocCount;
static int testCallocCount;
static int testReallocCount;
static int testFreeCount;
static void *testMalloc(size_t size) {
testMallocCount++;
return malloc(size);
}
static void *testCalloc(size_t count, size_t size) {
testCallocCount++;
return calloc(count, size);
}
static void *testRealloc(void *ptr, size_t size) {
testReallocCount++;
return realloc(ptr, size);
}
static void testFree(void *ptr) {
testFreeCount++;
free(ptr);
}
TEST(YogaTest, memory_func_default) {
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
YGSetMemoryFuncs(NULL, NULL, NULL, NULL);
const YGNodeRef root = YGNodeNew();
const YGNodeRef root_child0 = YGNodeNew();
YGNodeInsertChild(root, root_child0, 0);
YGNodeFreeRecursive(root);
}
TEST(YogaTest, memory_func_test_funcs) {
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
YGSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree);
const YGNodeRef root = YGNodeNew();
for (int i = 0; i < 10; i++) {
const YGNodeRef child = YGNodeNew();
YGNodeInsertChild(root, child, 0);
}
YGNodeFreeRecursive(root);
ASSERT_NE(testMallocCount, 0);
ASSERT_EQ(testCallocCount, 0);
ASSERT_NE(testReallocCount, 0);
ASSERT_NE(testFreeCount, 0);
YGSetMemoryFuncs(NULL, NULL, NULL, NULL);
}
#if GTEST_HAS_DEATH_TEST
TEST(YogaDeathTest, memory_func_assert_zero_nodes) {
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
const YGNodeRef root = YGNodeNew();
ASSERT_DEATH(YGSetMemoryFuncs(&testMalloc, &testCalloc, &testRealloc, &testFree),
"Cannot set memory functions: all node must be freed first");
YGNodeFreeRecursive(root);
}
TEST(YogaDeathTest, memory_func_assert_all_non_null) {
gNodeInstanceCount = 0; // Reset YGNode instance count for memory func test
gConfigInstanceCount = 0; // Reset YGConfig instance count for memory func test
ASSERT_DEATH(YGSetMemoryFuncs(NULL, &testCalloc, &testRealloc, &testFree),
"Cannot set memory functions: functions must be all NULL or Non-NULL");
}
#endif

View File

@@ -3816,23 +3816,3 @@ void *YGConfigGetContext(const YGConfigRef config) {
void YGConfigSetNodeClonedFunc(const YGConfigRef config, const YGNodeClonedFunc callback) { void YGConfigSetNodeClonedFunc(const YGConfigRef config, const YGNodeClonedFunc callback) {
config->cloneNodeCallback = callback; config->cloneNodeCallback = callback;
} }
void YGSetMemoryFuncs(YGMalloc ygmalloc, YGCalloc yccalloc, YGRealloc ygrealloc, YGFree ygfree) {
YGAssert(gNodeInstanceCount == 0 && gConfigInstanceCount == 0,
"Cannot set memory functions: all node must be freed first");
YGAssert((ygmalloc == NULL && yccalloc == NULL && ygrealloc == NULL && ygfree == NULL) ||
(ygmalloc != NULL && yccalloc != NULL && ygrealloc != NULL && ygfree != NULL),
"Cannot set memory functions: functions must be all NULL or Non-NULL");
if (ygmalloc == NULL || yccalloc == NULL || ygrealloc == NULL || ygfree == NULL) {
gYGMalloc = &malloc;
gYGCalloc = &calloc;
gYGRealloc = &realloc;
gYGFree = &free;
} else {
gYGMalloc = ygmalloc;
gYGCalloc = yccalloc;
gYGRealloc = ygrealloc;
gYGFree = ygfree;
}
}

View File

@@ -279,7 +279,4 @@ WIN_EXPORT YGConfigRef YGConfigGetDefault(void);
WIN_EXPORT void YGConfigSetContext(const YGConfigRef config, void *context); WIN_EXPORT void YGConfigSetContext(const YGConfigRef config, void *context);
WIN_EXPORT void *YGConfigGetContext(const YGConfigRef config); WIN_EXPORT void *YGConfigGetContext(const YGConfigRef config);
WIN_EXPORT void
YGSetMemoryFuncs(YGMalloc ygmalloc, YGCalloc yccalloc, YGRealloc ygrealloc, YGFree ygfree);
YG_EXTERN_C_END YG_EXTERN_C_END