Skip to content

Commit 717eed2

Browse files
committed
Improve CPlusPlus code gen
1 parent 7b9254f commit 717eed2

File tree

84 files changed

+219
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+219
-221
lines changed

Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-ArrayStructure_Int32_3.verified.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct Person {
1111
std::u32string_view name;
1212
const Person* other;
1313

14-
Person(const int32_t age, const std::u32string_view name, const Person* other) : age(age), name(name), other(other) { }
14+
constexpr Person(const int32_t age, const std::u32string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1515
};
1616
class ArrayStructure_Int32_3 final
1717
{
@@ -21,7 +21,7 @@ static constexpr std::array<int32_t, 3> keys = {
2121

2222
public:
2323
[[nodiscard]]
24-
static bool contains(const int32_t key) noexcept
24+
static constexpr bool contains(const int32_t key) noexcept
2525
{
2626
if (key < 1 || key > 3)
2727
return false;
@@ -33,12 +33,12 @@ public:
3333
}
3434
return false;
3535
}
36-
static inline std::array<Person*, 3> values = {
36+
inline static const std::array<Person*, 3> values = {
3737
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)), new Person(2, U"Billy", nullptr), new Person(3, U"Bibi", nullptr)
3838
};
3939

4040
[[nodiscard]]
41-
static bool try_lookup(const int32_t key, const Person*& value) noexcept
41+
static constexpr bool try_lookup(const int32_t key, const Person*& value) noexcept
4242
{
4343
if (key < 1 || key > 3)
4444
return false;

Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-BinarySearchStructure_Int32_3.verified.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct Person {
1111
std::u32string_view name;
1212
const Person* other;
1313

14-
Person(const int32_t age, const std::u32string_view name, const Person* other) : age(age), name(name), other(other) { }
14+
constexpr Person(const int32_t age, const std::u32string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1515
};
1616
class BinarySearchStructure_Int32_3 final
1717
{
@@ -21,7 +21,7 @@ class BinarySearchStructure_Int32_3 final
2121

2222
public:
2323
[[nodiscard]]
24-
static bool contains(const int32_t key) noexcept
24+
static constexpr bool contains(const int32_t key) noexcept
2525
{
2626
if (key < 1 || key > 3)
2727
return false;
@@ -43,12 +43,12 @@ public:
4343

4444
return false;
4545
}
46-
static inline std::array<Person*, 3> values = {
46+
inline static const std::array<Person*, 3> values = {
4747
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)), new Person(2, U"Billy", nullptr), new Person(3, U"Bibi", nullptr)
4848
};
4949

5050
[[nodiscard]]
51-
static bool try_lookup(const int32_t key, const Person*& value) noexcept
51+
static constexpr bool try_lookup(const int32_t key, const Person*& value) noexcept
5252
{
5353
if (key < 1 || key > 3)
5454
return false;

Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-ConditionalStructure_Int32_3.verified.txt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ struct Person {
1111
std::u32string_view name;
1212
const Person* other;
1313

14-
Person(const int32_t age, const std::u32string_view name, const Person* other) : age(age), name(name), other(other) { }
14+
constexpr Person(const int32_t age, const std::u32string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1515
};
1616
class ConditionalStructure_Int32_3 final
1717
{
1818
public:
1919
[[nodiscard]]
20-
static bool contains(const int32_t key) noexcept
20+
static constexpr bool contains(const int32_t key) noexcept
2121
{
2222

2323

@@ -26,15 +26,14 @@ public:
2626

2727
return false;
2828
}
29-
static inline std::array<Person*, 3> values = {
30-
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)), new Person(2, U"Billy", nullptr), new Person(3, U"Bibi", nullptr)
29+
inline static const std::array<Person*, 3> values = {
30+
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)), new Person(2, U"Billy", nullptr), new Person(3, U"Bibi", nullptr)
3131
};
3232

3333
[[nodiscard]]
34-
static bool try_lookup(const int32_t key, const Person*& value) noexcept
34+
static constexpr bool try_lookup(const int32_t key, const Person*& value) noexcept
3535
{
3636

37-
3837
if (key == 1)
3938
{
4039
value = values[0];
@@ -51,7 +50,6 @@ public:
5150
return true;
5251
}
5352

54-
5553
value = nullptr;
5654
return false;
5755
}

Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-HashTablePerfectStructure_Int32_3.verified.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct Person {
1111
std::u32string_view name;
1212
const Person* other;
1313

14-
Person(const int32_t age, const std::u32string_view name, const Person* other) : age(age), name(name), other(other) { }
14+
constexpr Person(const int32_t age, const std::u32string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1515
};
1616
class HashTablePerfectStructure_Int32_3 final
1717
{
@@ -21,7 +21,7 @@ struct e
2121

2222
const Person* value;
2323

24-
e(const int32_t key, const Person* value)
24+
constexpr e(const int32_t key, const Person* value) noexcept
2525
: key(key), value(value) {}
2626
};
2727
inline static const std::array<e, 3> entries = {
@@ -35,7 +35,7 @@ inline static const std::array<e, 3> entries = {
3535

3636
public:
3737
[[nodiscard]]
38-
static bool contains(const int32_t key) noexcept
38+
static constexpr bool contains(const int32_t key) noexcept
3939
{
4040
if (key < 1 || key > 3)
4141
return false;
@@ -47,7 +47,7 @@ public:
4747
return key == entry.key;
4848
}
4949
[[nodiscard]]
50-
static bool try_lookup(const int32_t key, const Person*& value) noexcept
50+
static constexpr bool try_lookup(const int32_t key, const Person*& value) noexcept
5151
{
5252
if (key < 1 || key > 3)
5353
return false;

Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-HashTableStructure_Int32_3.verified.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct Person {
1111
std::u32string_view name;
1212
const Person* other;
1313

14-
Person(const int32_t age, const std::u32string_view name, const Person* other) : age(age), name(name), other(other) { }
14+
constexpr Person(const int32_t age, const std::u32string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1515
};
1616
class HashTableStructure_Int32_3 final
1717
{
@@ -21,16 +21,16 @@ class HashTableStructure_Int32_3 final
2121
int8_t next;
2222

2323
const Person* value;
24-
e(const int8_t next, const int32_t key, const Person* value)
25-
: next(next), key(key), value(value) {}
24+
e(const int32_t key, const int8_t next, const Person* value)
25+
: key(key), next(next), value(value) {}
2626
};
2727

2828
static constexpr std::array<int8_t, 3> buckets = {
2929
3, 1, 2
3030
};
3131

3232
inline static const std::array<e, 3> entries = {
33-
e(-1, 1, new Person(1, U"Bob", new Person(4, U"Anna", nullptr))), e(-1, 2, new Person(2, U"Billy", nullptr)), e(-1, 3, new Person(3, U"Bibi", nullptr))
33+
e(1, -1, new Person(1, U"Bob", new Person(4, U"Anna", nullptr))), e(2, -1, new Person(2, U"Billy", nullptr)), e(3, -1, new Person(3, U"Bibi", nullptr))
3434
};
3535

3636
static constexpr uint64_t get_hash(const int32_t value) noexcept
@@ -40,14 +40,14 @@ class HashTableStructure_Int32_3 final
4040

4141
public:
4242
[[nodiscard]]
43-
static bool contains(const int32_t key) noexcept
43+
static constexpr bool contains(const int32_t key) noexcept
4444
{
4545
if (key < 1 || key > 3)
4646
return false;
4747

4848
const uint64_t hash = get_hash(key);
4949
const size_t index = hash % 3;
50-
int8_t i = buckets[index] - static_cast<int8_t>(1);
50+
int8_t i = static_cast<int8_t>(buckets[index] - 1);
5151

5252
while (i >= 0)
5353
{
@@ -62,14 +62,14 @@ public:
6262
return false;
6363
}
6464
[[nodiscard]]
65-
static bool try_lookup(const int32_t key, const Person*& value) noexcept
65+
static constexpr bool try_lookup(const int32_t key, const Person*& value) noexcept
6666
{
6767
if (key < 1 || key > 3)
6868
return false;
6969

7070
const uint64_t hash = get_hash(key);
7171
const size_t index = hash % 3;
72-
int8_t i = buckets[index] - static_cast<int8_t>(1);
72+
int8_t i = static_cast<int8_t>(buckets[index] - 1);
7373

7474
while (i >= 0)
7575
{

Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-KeyLengthStructure_String_3.verified.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ struct Person {
1111
std::string_view name;
1212
const Person* other;
1313

14-
Person(const int32_t age, const std::string_view name, const Person* other) : age(age), name(name), other(other) { }
14+
constexpr Person(const int32_t age, const std::string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1515
};
1616
class KeyLengthStructure_String_3 final
1717
{
1818
static constexpr std::array<int32_t, 3> offsets = {
1919
0, 1, 2
2020
};
21-
static inline std::array<Person*, 3> values = {
21+
inline static const std::array<Person*, 3> values = {
2222
new Person(1, "Bob", new Person(4, "Anna", nullptr)), new Person(2, "Billy", nullptr), new Person(3, "Bibi", nullptr)
2323
};
2424
static constexpr std::array<std::string_view, 3> keys = {
@@ -27,14 +27,15 @@ class KeyLengthStructure_String_3 final
2727

2828
public:
2929
[[nodiscard]]
30-
static bool contains(const std::string_view key) noexcept
30+
static constexpr bool contains(const std::string_view key) noexcept
3131
{
3232
if (const size_t len = key.length(); len < 1u || len > 3u)
3333
return false;
3434

3535
return key == keys[key.length() - 1];
36-
}[[nodiscard]]
37-
static bool try_lookup(const std::string_view key, const Person*& value) noexcept
36+
}
37+
[[nodiscard]]
38+
static constexpr bool try_lookup(const std::string_view key, const Person*& value) noexcept
3839
{
3940
if (const size_t len = key.length(); len < 1u || len > 3u)
4041
return false;

Src/FastData.Generator.CPlusPlus.Tests/Features/ObjectSupportTest-SingleValueStructure_Int32_1.verified.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct Person {
1111
std::u32string_view name;
1212
const Person* other;
1313

14-
Person(const int32_t age, const std::u32string_view name, const Person* other) : age(age), name(name), other(other) { }
14+
constexpr Person(const int32_t age, const std::u32string_view name, const Person* other) noexcept : age(age), name(name), other(other) { }
1515
};
1616
class SingleValueStructure_Int32_1 final
1717
{
@@ -21,10 +21,10 @@ public:
2121
{
2222
return key == 1;
2323
}
24-
static inline auto stored_value = new Person(1, U"Bob", new Person(4, U"Anna", nullptr));
24+
static inline const auto stored_value = new Person(1, U"Bob", new Person(4, U"Anna", nullptr));
2525

2626
[[nodiscard]]
27-
static bool try_lookup(const int32_t key, const Person*& value) noexcept
27+
static constexpr bool try_lookup(const int32_t key, const Person*& value) noexcept
2828
{
2929
if (key == 1)
3030
{

Src/FastData.Generator.CPlusPlus.Tests/Vectors/ArrayStructure_Byte_3.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static constexpr std::array<uint8_t, 3> keys = {
1414

1515
public:
1616
[[nodiscard]]
17-
static bool contains(const uint8_t key) noexcept
17+
static constexpr bool contains(const uint8_t key) noexcept
1818
{
1919
if (key < 0 || key > std::numeric_limits<uint8_t>::max())
2020
return false;

Src/FastData.Generator.CPlusPlus.Tests/Vectors/ArrayStructure_Char_3.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static constexpr std::array<char, 3> keys = {
1414

1515
public:
1616
[[nodiscard]]
17-
static bool contains(const char key) noexcept
17+
static constexpr bool contains(const char key) noexcept
1818
{
1919
if (key < 0 || key > 127)
2020
return false;

Src/FastData.Generator.CPlusPlus.Tests/Vectors/ArrayStructure_Double_4.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static constexpr std::array<double, 4> keys = {
1414

1515
public:
1616
[[nodiscard]]
17-
static bool contains(const double key) noexcept
17+
static constexpr bool contains(const double key) noexcept
1818
{
1919
if (key < std::numeric_limits<double>::lowest() || key > std::numeric_limits<double>::max())
2020
return false;

0 commit comments

Comments
 (0)