Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into reduce.sn
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Nov 26, 2024
2 parents 0c530c8 + cc97853 commit e647c09
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/mixed_arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,9 @@ template<typename SubType, typename T> class ArenaVectorBase {
void operator=(SubType& other) { set(other); }

void swap(SubType& other) {
data = other.data;
usedElements = other.usedElements;
allocatedElements = other.allocatedElements;

other.data = nullptr;
other.usedElements = other.allocatedElements = 0;
std::swap(data, other.data);
std::swap(usedElements, other.usedElements);
std::swap(allocatedElements, other.allocatedElements);
}

// iteration
Expand Down
1 change: 1 addition & 0 deletions test/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ include_directories(../../third_party/googletest/googletest/include)
include_directories(../../src/wasm)

set(unittest_SOURCES
arena.cpp
binary-reader.cpp
cfg.cpp
dfa_minimization.cpp
Expand Down
39 changes: 39 additions & 0 deletions test/gtest/arena.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "mixed_arena.h"
#include "gtest/gtest.h"

using ArenaTest = ::testing::Test;

TEST_F(ArenaTest, Swap) {
MixedArena arena;

ArenaVector<int> a(arena);
a.push_back(10);
a.push_back(20);

ArenaVector<int> b(arena);

EXPECT_EQ(a.size(), 2U);
EXPECT_EQ(b.size(), 0U);

a.swap(b);

EXPECT_EQ(a.size(), 0U);
EXPECT_EQ(b.size(), 2U);

a.swap(b);

EXPECT_EQ(a.size(), 2U);
EXPECT_EQ(b.size(), 0U);

// Now reverse a and b. The swap should be the same.

b.swap(a);

EXPECT_EQ(a.size(), 0U);
EXPECT_EQ(b.size(), 2U);

b.swap(a);

EXPECT_EQ(a.size(), 2U);
EXPECT_EQ(b.size(), 0U);
}

0 comments on commit e647c09

Please sign in to comment.