Quellcode durchsuchen

Caches TrimmedLength

devmil vor 4 Jahren
Ursprung
Commit
f6c3bddb0d
1 geänderte Dateien mit 14 neuen und 0 gelöschten Zeilen
  1. 14 0
      lib/buffer/buffer_line.dart

+ 14 - 0
lib/buffer/buffer_line.dart

@@ -36,6 +36,7 @@ class BufferLine {
   bool isWrapped;
 
   int _maxCols = 64;
+  int? _currentTrimmedLength;
 
   void ensure(int length) {
     final expectedLengthInBytes = length * _cellSize;
@@ -75,6 +76,7 @@ class BufferLine {
     for (var i = moveEnd; i < bufferEnd; i++) {
       cells[i] = 0x00;
     }
+    _currentTrimmedLength = null;
   }
 
   void insertN(int index, int count) {
@@ -104,6 +106,7 @@ class BufferLine {
     for (var i = moveStart; i < moveStart + moveOffset; i++) {
       cells[i] = 0x00;
     }
+    _currentTrimmedLength = null;
   }
 
   void clear() {
@@ -123,6 +126,7 @@ class BufferLine {
   void cellClear(int index) {
     _cells.setInt64(index * _cellSize, 0x00);
     _cells.setInt64(index * _cellSize + 8, 0x00);
+    _currentTrimmedLength = null;
   }
 
   void cellInitialize(
@@ -137,6 +141,7 @@ class BufferLine {
     _cells.setInt32(cell + _cellBgColor, cursor.bg);
     _cells.setInt8(cell + _cellWidth, width);
     _cells.setInt8(cell + _cellFlags, cursor.flags);
+    _currentTrimmedLength = null;
   }
 
   bool cellHasContent(int index) {
@@ -152,6 +157,7 @@ class BufferLine {
 
   void cellSetContent(int index, int content) {
     _cells.setInt32(index * _cellSize + _cellContent, content);
+    _currentTrimmedLength = null;
   }
 
   int cellGetFgColor(int index) {
@@ -196,6 +202,7 @@ class BufferLine {
 
   void cellSetWidth(int index, int width) {
     _cells.setInt8(index * _cellSize + _cellWidth, width);
+    _currentTrimmedLength = null;
   }
 
   void cellClearFlags(int index) {
@@ -219,9 +226,13 @@ class BufferLine {
     cellSetBgColor(index, cursor.bg);
     cellSetFlags(index, cursor.flags);
     cellSetWidth(index, 0);
+    _currentTrimmedLength = null;
   }
 
   int getTrimmedLength([int? cols]) {
+    if (_currentTrimmedLength != null) {
+      return _currentTrimmedLength!;
+    }
     if (cols == null) {
       cols = _maxCols;
     }
@@ -231,9 +242,11 @@ class BufferLine {
         for (int j = 0; j <= i; j++) {
           length += cellGetWidth(j);
         }
+        _currentTrimmedLength = length;
         return length;
       }
     }
+    _currentTrimmedLength = 0;
     return 0;
   }
 
@@ -250,6 +263,7 @@ class BufferLine {
     for (var i = 0; i < intsToCopy; i++) {
       cells[dstStart + i] = srcCells[srcStart + i];
     }
+    _currentTrimmedLength = null;
   }
 
   // int cellGetHash(int index) {