a2c31f7490
This is a reland of https://chromium-review.googlesource.com/c/v8/v8/+/2688058 This CL is part of a series that adds the C++ implementation of SwissNameDictionary, a deterministic property backing store based on Swiss Tables. This CL adds the initialization code, factory functions and a canonical SwissNameDictionary plus all helpers required for that. Bug: v8:11388 Change-Id: I9cf66a3fa755288f7730f55abfb6e6cea82f6b03 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2703653 Commit-Queue: Frank Emrich <emrich@google.com> Reviewed-by: Igor Sheludko <ishell@chromium.org> Reviewed-by: Marja Hölttä <marja@chromium.org> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Cr-Commit-Position: refs/heads/master@{#72857}
82 lines
2.5 KiB
C++
82 lines
2.5 KiB
C++
// Copyright 2021 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "src/objects/swiss-name-dictionary-inl.h"
|
|
#include "test/cctest/cctest.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
namespace test_swiss_hash_table {
|
|
|
|
TEST(CapacityFor) {
|
|
for (int elements = 0; elements <= 32; elements++) {
|
|
int capacity = SwissNameDictionary::CapacityFor(elements);
|
|
if (elements == 0) {
|
|
CHECK_EQ(0, capacity);
|
|
} else if (elements <= 3) {
|
|
CHECK_EQ(4, capacity);
|
|
} else if (elements == 4) {
|
|
CHECK_IMPLIES(SwissNameDictionary::kGroupWidth == 8, capacity == 8);
|
|
CHECK_IMPLIES(SwissNameDictionary::kGroupWidth == 16, capacity == 4);
|
|
} else if (elements <= 7) {
|
|
CHECK_EQ(8, capacity);
|
|
} else if (elements <= 14) {
|
|
CHECK_EQ(16, capacity);
|
|
} else if (elements <= 28) {
|
|
CHECK_EQ(32, capacity);
|
|
} else if (elements <= 32) {
|
|
CHECK_EQ(64, capacity);
|
|
}
|
|
}
|
|
}
|
|
|
|
TEST(MaxUsableCapacity) {
|
|
CHECK_EQ(0, SwissNameDictionary::MaxUsableCapacity(0));
|
|
CHECK_IMPLIES(SwissNameDictionary::kGroupWidth == 8,
|
|
SwissNameDictionary::MaxUsableCapacity(4) == 3);
|
|
CHECK_IMPLIES(SwissNameDictionary::kGroupWidth == 16,
|
|
SwissNameDictionary::MaxUsableCapacity(4) == 4);
|
|
CHECK_EQ(7, SwissNameDictionary::MaxUsableCapacity(8));
|
|
CHECK_EQ(14, SwissNameDictionary::MaxUsableCapacity(16));
|
|
CHECK_EQ(28, SwissNameDictionary::MaxUsableCapacity(32));
|
|
}
|
|
|
|
TEST(SizeFor) {
|
|
int baseline = HeapObject::kHeaderSize +
|
|
// prefix:
|
|
4 +
|
|
// capacity:
|
|
4 +
|
|
// meta table:
|
|
kTaggedSize;
|
|
|
|
int size_0 = baseline +
|
|
// ctrl table:
|
|
SwissNameDictionary::kGroupWidth;
|
|
|
|
int size_4 = baseline +
|
|
// data table:
|
|
4 * 2 * kTaggedSize +
|
|
// ctrl table:
|
|
4 + SwissNameDictionary::kGroupWidth +
|
|
// property details table:
|
|
4;
|
|
|
|
int size_8 = baseline +
|
|
// data table:
|
|
8 * 2 * kTaggedSize +
|
|
// ctrl table:
|
|
8 + SwissNameDictionary::kGroupWidth +
|
|
// property details table:
|
|
8;
|
|
|
|
CHECK_EQ(SwissNameDictionary::SizeFor(0), size_0);
|
|
CHECK_EQ(SwissNameDictionary::SizeFor(4), size_4);
|
|
CHECK_EQ(SwissNameDictionary::SizeFor(8), size_8);
|
|
}
|
|
|
|
} // namespace test_swiss_hash_table
|
|
} // namespace internal
|
|
} // namespace v8
|