Skip to content

Commit

Permalink
ValuePool (#1534)
Browse files Browse the repository at this point in the history
Summary:


| | Before | After | Δ |
| `sizeof(yoga::Style)` | 208B  | 144B | -64B/-31% |
| `sizeof(yoga::Node)` | 640B  | 576B | -64B/-10% |
| `sizeof(YogaLayoutableShadowNode) ` |  920B | 856B | -64B/-7% |
| `sizeof(YogaLayoutableShadowNode) + sizeof(YogaStylableProps)` | 1296B  | 1168B | -128B/-10% |
| `sizeof(ViewShadowNode)`  |  920B | 856B | -64B/-7% |
| `sizeof(ViewShadowNode) + sizeof(ViewShadowNodeProps)` | 2000B  | 1872B | -128B/-6% |

Differential Revision: D52223122
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Dec 23, 2023
1 parent 94e7336 commit 4f63e56
Show file tree
Hide file tree
Showing 10 changed files with 571 additions and 534 deletions.
291 changes: 0 additions & 291 deletions tests/CompactValueTest.cpp

This file was deleted.

96 changes: 96 additions & 0 deletions tests/SmallValueBufferTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <gtest/gtest.h>
#include <yoga/style/SmallValueBuffer.h>

namespace facebook::yoga {

constexpr size_t kBufferSize = 4;

TEST(SmallValueBuffer, copy_assignment_with_overflow) {
std::array<uint16_t, kBufferSize + 1> handles;

SmallValueBuffer<kBufferSize> buffer1;
for (size_t i = 0; i < kBufferSize + 1; ++i) {
handles[i] = buffer1.push(static_cast<uint32_t>(i));
}

SmallValueBuffer<kBufferSize> buffer2 = buffer1;
for (size_t i = 0; i < kBufferSize + 1; ++i) {
EXPECT_EQ(buffer2.get32(handles[i]), i);
}

auto handle = buffer1.push(42u);
EXPECT_EQ(buffer1.get32(handle), 42);

EXPECT_THROW({ buffer2.get32(handle); }, std::logic_error);
}

TEST(SmallValueBuffer, push_32) {
auto magic = 88567114u;

SmallValueBuffer<kBufferSize> buffer;
auto handle = buffer.push(magic);
EXPECT_EQ(buffer.get32(handle), magic);
}

TEST(SmallValueBuffer, push_overflow) {
uint32_t magic1 = 88567114u;
uint32_t magic2 = 351012214u;
uint32_t magic3 = 146122128u;
uint32_t magic4 = 2171092154u;
uint32_t magic5 = 2269016953u;

SmallValueBuffer<kBufferSize> buffer;
EXPECT_EQ(buffer.get32(buffer.push(magic1)), magic1);
EXPECT_EQ(buffer.get32(buffer.push(magic2)), magic2);
EXPECT_EQ(buffer.get32(buffer.push(magic3)), magic3);
EXPECT_EQ(buffer.get32(buffer.push(magic4)), magic4);
EXPECT_EQ(buffer.get32(buffer.push(magic5)), magic5);
}

TEST(SmallValueBuffer, push_64) {
uint64_t magic = 88567114ull;

SmallValueBuffer<kBufferSize> buffer;
auto handle = buffer.push(magic);
EXPECT_EQ(buffer.get64(handle), magic);
}

TEST(SmallValueBuffer, push_64_overflow) {
uint64_t magic1 = 1401612388342512ull;
uint64_t magic2 = 118712305386210ull;
uint64_t magic3 = 752431801563359011ull;
uint64_t magic4 = 118138934255546108ull;
uint64_t magic5 = 237115443124116111ull;

SmallValueBuffer<kBufferSize> buffer;
EXPECT_EQ(buffer.get64(buffer.push(magic1)), magic1);
EXPECT_EQ(buffer.get64(buffer.push(magic2)), magic2);
EXPECT_EQ(buffer.get64(buffer.push(magic3)), magic3);
EXPECT_EQ(buffer.get64(buffer.push(magic4)), magic4);
EXPECT_EQ(buffer.get64(buffer.push(magic5)), magic5);
}

TEST(SmallValueBuffer, push_64_after_32) {}

TEST(SmallValueBuffer, push_32_after_64) {}

TEST(SmallValueBuffer, get32_oob) {}

TEST(SmallValueBuffer, get64_oob) {}

TEST(SmallValueBuffer, replace_32_with_32) {}

TEST(SmallValueBuffer, replace_32_with_64) {}

TEST(SmallValueBuffer, replace_64_with_32) {}

TEST(SmallValueBuffer, replace_64_with_64) {}

} // namespace facebook::yoga
Loading

0 comments on commit 4f63e56

Please sign in to comment.