Skip to content

Commit

Permalink
Fixed|libcore: Behavior of String/Block move constructors/assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent a242764 commit 74a2b15
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions doomsday/libs/core/include/de/data/block.h
Expand Up @@ -127,6 +127,7 @@ class DE_PUBLIC Block
Block &operator+=(const IByteArray &byteArray);

Block &operator=(const Block &other);
Block &operator=(Block &&moved);
Block &operator=(const IByteArray &byteArray);

Block compressed(int level = -1) const;
Expand Down
7 changes: 1 addition & 6 deletions doomsday/libs/core/include/de/data/string.h
Expand Up @@ -262,12 +262,7 @@ class DE_PUBLIC String : public IByteArray

inline String &operator=(String &&moved)
{
if (_str.chars.i)
{
deinit_String(&_str);
}
_str = moved._str;
zap(moved._str);
set_String(&_str, &moved._str);
return *this;
}

Expand Down
11 changes: 8 additions & 3 deletions doomsday/libs/core/src/data/block.cpp
Expand Up @@ -51,8 +51,7 @@ Block::Block(const Block &other)

Block::Block(Block &&moved)
{
_block = moved._block;
iZap(moved._block);
set_Block(&_block, &moved._block);
}

Block::Block(const char *nullTerminatedCStr)
Expand Down Expand Up @@ -274,10 +273,16 @@ Block &Block::operator+=(const IByteArray &byteArray)

Block &Block::operator=(const Block &other)
{
set_Block(&_block, other);
set_Block(&_block, &other._block);
return *this;
}

Block &Block::operator=(Block &&moved)
{
set_Block(&_block, &moved._block);
return *this;
}

Block &Block::operator=(const IByteArray &byteArray)
{
copyFrom(byteArray, 0, byteArray.size());
Expand Down
5 changes: 2 additions & 3 deletions doomsday/libs/core/src/data/string.cpp
@@ -1,7 +1,7 @@
/*
* The Doomsday Engine Project -- libcore
*
* Copyright © 2004-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
* Copyright © 2004-2018 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* LGPL: http://www.gnu.org/licenses/lgpl.html
Expand Down Expand Up @@ -46,8 +46,7 @@ String::String(const String &other)

String::String(String &&moved)
{
_str = moved._str;
iZap(moved._str);
initCopy_String(&_str, &moved._str);
}

String::String(const Block &bytes)
Expand Down

0 comments on commit 74a2b15

Please sign in to comment.