Skip to content

Commit 864f74c

Browse files
committed
Do not use shared_ptr for comment blocks
1 parent bdbe6bc commit 864f74c

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

include/scratchcpp/comment.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class LIBSCRATCHCPP_EXPORT Comment : public Entity
2020
const std::string &blockId() const;
2121
void setBlockId(const std::string id);
2222

23-
std::shared_ptr<Block> block() const;
24-
void setBlock(std::shared_ptr<Block> block);
23+
Block *block() const;
24+
void setBlock(Block *block);
2525

2626
double x() const;
2727
void setX(double x);

src/engine/internal/engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void Engine::resolveIds()
182182
block->setComment(comment);
183183

184184
if (comment) {
185-
comment->setBlock(block);
185+
comment->setBlock(block.get());
186186
assert(comment->blockId() == block->id());
187187
}
188188
}

src/scratch/comment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ void Comment::setBlockId(const std::string id)
2828
}
2929

3030
/*! Returns the block the comment is attached to. */
31-
std::shared_ptr<Block> Comment::block() const
31+
Block *Comment::block() const
3232
{
3333
return impl->block;
3434
}
3535

3636
/*! Sets the block the comment is attached to. */
37-
void Comment::setBlock(std::shared_ptr<Block> block)
37+
void Comment::setBlock(Block *block)
3838
{
3939
impl->block = block;
4040

src/scratch/comment_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct CommentPrivate
1616
CommentPrivate(const CommentPrivate &) = delete;
1717

1818
std::string blockId;
19-
std::shared_ptr<Block> block;
19+
Block *block = nullptr;
2020
double x = 0;
2121
double y = 0;
2222
double width = 200;

test/load_project/load_project_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ TEST(LoadProjectTest, LoadTestProject)
424424
auto commentBlock = sprite2->blockAt(sprite2->findBlock("e"));
425425
ASSERT_EQ(comment->id(), "w");
426426
ASSERT_EQ(comment->blockId(), "e");
427-
ASSERT_EQ(comment->block(), commentBlock);
427+
ASSERT_EQ(comment->block(), commentBlock.get());
428428
ASSERT_EQ(comment->x(), 247.3981475830078);
429429
ASSERT_EQ(comment->y(), 208);
430430
ASSERT_EQ(comment->width(), 189.62969970703125);

test/scratch_classes/comment_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ TEST(CommentTest, Block)
2929
ASSERT_TRUE(comment.blockId().empty());
3030

3131
auto block = std::make_shared<Block>("abc", "");
32-
comment.setBlock(block);
33-
ASSERT_EQ(comment.block(), block);
32+
comment.setBlock(block.get());
33+
ASSERT_EQ(comment.block(), block.get());
3434
ASSERT_EQ(comment.blockId(), "abc");
3535

3636
comment.setBlock(nullptr);

0 commit comments

Comments
 (0)