5
5
import 'dart:async' ;
6
6
import 'dart:convert' ;
7
7
import 'dart:io' ;
8
+ import 'dart:typed_data' ;
8
9
9
10
import 'io_utils.dart' ;
10
11
import 'legacy_messages.dart' ;
@@ -19,7 +20,7 @@ abstract class DartLanguageServerBenchmark {
19
20
bool _launched = false ;
20
21
bool _exited = false ;
21
22
Completer <bool > _analyzingCompleter = Completer ();
22
- final _buffer = < int > [] ;
23
+ final _buffer = _Uint8ListHelper () ;
23
24
int ? _headerContentLength;
24
25
bool _printedVmServiceStuff = false ;
25
26
final String executableToUse;
@@ -347,11 +348,11 @@ abstract class DartLanguageServerBenchmark {
347
348
_buffer.length % 1000 == 0 ) {
348
349
print (
349
350
'DEBUG MESSAGE: Stdout buffer with length ${_buffer .length } so far: '
350
- '${utf8 .decode (_buffer )}' ,
351
+ '${utf8 .decode (_buffer . view () )}' ,
351
352
);
352
353
}
353
354
if (_lsp == true && _headerContentLength == null && _endsWithCrLfCrLf ()) {
354
- String headerRaw = utf8.decode (_buffer);
355
+ String headerRaw = utf8.decode (_buffer. view () );
355
356
_buffer.clear ();
356
357
// Use a regex that makes the '\r' optional to handle "The Dart VM service
357
358
// is listening on [..." message - at least on linux - being \n terminated
@@ -377,7 +378,7 @@ abstract class DartLanguageServerBenchmark {
377
378
_headerContentLength != null &&
378
379
_buffer.length == _headerContentLength! ) ||
379
380
(_lsp == false && _endsWithLf ())) {
380
- String messageString = utf8.decode (_buffer);
381
+ String messageString = utf8.decode (_buffer. view () );
381
382
_buffer.clear ();
382
383
_headerContentLength = null ;
383
384
@@ -515,6 +516,34 @@ class OutstandingRequest {
515
516
}
516
517
}
517
518
519
+ class _Uint8ListHelper {
520
+ Uint8List data;
521
+ int length = 0 ;
522
+ _Uint8ListHelper () : data = Uint8List (1024 );
523
+
524
+ int operator [](int index) {
525
+ if (index < 0 || index >= length) throw 'Out of bounds: $index ' ;
526
+ return data[index];
527
+ }
528
+
529
+ void add (int i) {
530
+ if (length == data.length) {
531
+ var newData = Uint8List (length * 2 );
532
+ newData.setRange (0 , length, data);
533
+ data = newData;
534
+ }
535
+ data[length++ ] = i;
536
+ }
537
+
538
+ void clear () {
539
+ length = 0 ;
540
+ }
541
+
542
+ Uint8List view () {
543
+ return Uint8List .sublistView (data, 0 , length);
544
+ }
545
+ }
546
+
518
547
extension on List <MemoryInfo > {
519
548
void addInfoMaybe (String description, int ? value) {
520
549
if (value == null ) return ;
0 commit comments