Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Add `PriorityQueue` (#392).
* Add support for Weak references (#388).
* Clarify difference between `List` and `pure/List` in doc comments (#386).
* Fix memory leak bugs in `List.addRepeat<T>` and `List.removeLast<T>` (#343).

## 1.0.0

Expand Down
4 changes: 2 additions & 2 deletions src/List.mo
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ module {
var cnt = count;
while (cnt > 0) {
let db_size = data_block_size(list.blockIndex);
if (list.elementIndex == 0 and db_size <= cnt) {
if (list.elementIndex == 0 and db_size <= cnt and list.blocks[list.blockIndex].size() == 0) {
list.blocks[list.blockIndex] := VarArray.repeat<?T>(?initValue, db_size);
cnt -= db_size;
list.blockIndex += 1
Expand Down Expand Up @@ -470,7 +470,7 @@ module {

// Keep one totally empty block when removing
if (blockIndex + 2 < list.blocks.size()) {
if (list.blocks[blockIndex + 2].size() == 0) {
if (list.blocks[blockIndex + 2].size() > 0) {
list.blocks[blockIndex + 2] := [var]
}
};
Expand Down