Skip to content

Optimization suggestion for FileIO::doBuffer() #1763

Closed
@bobh66

Description

@bobh66

In FileIO::doBuffer() the error code is in the first byte of the buffer response, and the code shifts the entire buffer to overwrite the error code.

I think this can be optimized by simply setting readPos to 1 so that the next read of the buffer will skip the error code and start with the first byte of real data. No space in the buffer is wasted since there can only be BUFFER_SIZE bytes in the buffer anyway, so the first byte will be ignored instead of the last byte.

Let me know what you think.

Thanks

Bob

void File::doBuffer() {
  // If there are already char in buffer exit
  if (buffered > 0)
    return;

  // Try to buffer up to BUFFER_SIZE characters
  readPos = 0;
  uint8_t cmd[] = {'G', handle, BUFFER_SIZE - 1};
  buffered = bridge.transfer(cmd, 3, buffer, BUFFER_SIZE) - 1;
  //err = buff[0]; // First byte is error code
  if (buffered > 0) {
    // Ignore the error code in the first byte
    readPos++;
  }
}

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