Skip to content
Merged
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
22 changes: 12 additions & 10 deletions inkcpp/collections/restorable.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ class restorable_iter
{
public:
// Create an iterator moving from start (inclusive) to end (exclusive)
restorable_iter(ElementType* start, ElementType* end)
restorable_iter(int start, int end, ElementType* const& buffer)
: _current(start)
, _end(end)
, _buffer(buffer)
{
}

Expand All @@ -43,7 +44,7 @@ class restorable_iter
_current += dir;

// Make sure to skip over null items
while (isNull(*_current) && _current != _end) {
while (isNull(_buffer[_current]) && _current != _end) {
_current += dir;
}
}
Expand All @@ -57,20 +58,21 @@ class restorable_iter
}

// Get current element
inline ElementType* get() { return _current; }
inline ElementType* get() { return &_buffer[_current]; }

// Get current element (const)
inline const ElementType* get() const { return _current; }
inline const ElementType* get() const { return &_buffer[_current]; }

// Is iteration complete (opposite of is valid)
inline bool done() const { return _current == _end; }

private:
// Current point of iteration
ElementType* _current;
int _current;

// End point (non-valid)
ElementType* _end;
int _end;
ElementType* const& _buffer;
};

/**
Expand Down Expand Up @@ -157,14 +159,14 @@ class restorable : public snapshot_interface
using const_iterator = restorable_iter<const ElementType>;

// Iterator that begins at the end of the stack
iterator begin() { return iterator(&_buffer[_pos - 1], _buffer - 1); }
iterator begin() { return iterator(_pos - 1, -1, _buffer); }

const_iterator begin() const { return const_iterator(&_buffer[_pos - 1], _buffer - 1); }
const_iterator begin() const { return const_iterator(_pos - 1, -1, _buffer); }

// Iterator that points to the element past the beginning of the stack
iterator end() { return iterator(_buffer - 1, _buffer - 1); }
iterator end() { return iterator(-1, -1, _buffer); }

iterator end() const { return const_iterator(_buffer - 1, _buffer - 1); }
iterator end() const { return const_iterator(-1, -1, _buffer); }

// Push element onto the top of collection
ElementType& push(const ElementType& elem)
Expand Down
5 changes: 1 addition & 4 deletions inkcpp/stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,7 @@ offset_t basic_stack::pop_frame(frame_type* type, bool& eval)
entry* frame = iter.get();
if (frame->name != InvalidHash || frame->data.type() == value_type::none) {
pop();
iter = base::begin();
if (is_entry_null(*iter.get())) {
iter.next(is_entry_null);
}
iter.next(is_entry_null);
continue;
}

Expand Down
Loading