Skip to content

Buffer index when deleting an item #232

Closed
@priandsf

Description

@priandsf

buffer.remove() resets its first index when it gets empty with the code bellow:

      if(!buffer.length) {
        buffer.first = 1;
        buffer.next = 1;
      }

This actually has a few issues:

  • It resets it to 1 while it should better use startIndex. This has consequences when the start index is 0. Even better, it should use minIndex if it exists.
  • It does not reset eof. Suppose that we start from the following buffer {first=10, length=5, eof=true}. Now we remove the 5 elements in the buffer. It leads to a situation where first=1 but eof=true. As a result, it thinks that 1 is the latest element and thus it does not display the remaining ones up to 10.

I suggest the following fix:

      if(!buffer.length) {
        buffer.first = buffer.minIndex!==undefined ? buffer.minIndex : startIndex;
        buffer.next = buffer.first;
        buffer.eof = buffer.eof && buffer.first==buffer.maxIndex;
      }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions