getDirectAccess method

DirectTextAccess getDirectAccess()

Get direct access to internal arrays for performance-critical operations.

Implementation

DirectTextAccess getDirectAccess() {
  _checkNotDisposed();

  final len = _bindings.textBufferGetLength(_ptr);
  if (len == 0) {
    return DirectTextAccess(
      chars: Uint32List(0),
      foregrounds: Float32List(0),
      backgrounds: Float32List(0),
      attributes: Uint16List(0),
      length: 0,
    );
  }

  final charPtr = _bindings.textBufferGetCharPtr(_ptr);
  final attrPtr = _bindings.textBufferGetAttributesPtr(_ptr);

  return DirectTextAccess(
    chars: charPtr.asTypedList(len),
    foregrounds: _textBufferColors(len, foreground: true),
    backgrounds: _textBufferColors(len, foreground: false),
    attributes: attrPtr.asTypedList(len),
    length: len,
  );
}