Skip to content

Commit

Permalink
Remove unecessary extra 2 bytes from skips arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumbub committed Feb 27, 2022
1 parent 38b6e91 commit c3ab29a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/logic/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,22 @@ void Board::allocateBoardMemory(const uint& width, const uint& height) {
// Generate board with 1 cell of padding
const uint size = (width + PADDING) * (height + PADDING);
if (raw == nullptr) {
// (size + 1) for skip final values
raw = new Cell[size * 2 + (size + 1) * 2];
raw = new Cell[size * 4];
input = raw;
output = input + size;
inSkip = output + size;
outSkip = inSkip + 1 + size;
outSkip = inSkip + size;
}

clearSkips();
}

void Board::clearSkips() {
std::memset(&raw[rawSize * 2], false, (rawSize + 1) * 2);
std::memset(&raw[rawSize * 2], false, rawSize * 2);
}

Board::Board(const uint& width, const uint& height) {
setSize(width, height);
allocateBoardMemory(width, height);
}

Board::~Board() {
Expand Down
2 changes: 1 addition & 1 deletion src/logic/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ struct Board {

void setOutputToInput();
void setSize(const uint& width, const uint& height);
void allocateBoardMemory(const uint& width, const uint& height);
void clearSkips();
Board(const uint& width, const uint& height);
~Board();

private:
void allocateBoardMemory(const uint& width, const uint& height);
Board([[maybe_unused]] const Board& _){};
};

0 comments on commit c3ab29a

Please sign in to comment.