Files
sdk/pkg/analysis_server
Konstantin Shcheglov 8d3b6ce54c Use flattenedToList/flattenedToSet instead of generic expand().
It is faster.

[expand: 102]
[flattened: 131]
[flattened2: 37]

import 'package:collection/collection.dart';

main() {
  const outerLength = 100;
  const innerLength = 10;
  final listOfLists = List.generate(outerLength, (i) {
    return List.generate(innerLength, (j) => i * innerLength + j);
  });

  for (var i = 0; i < 10; i++) {
    f(listOfLists);
  }
}

void f(List<List<int>> listOfLists) {
  const repeatCount = 10000;

  {
    final timer = Stopwatch()..start();
    for (var i = 0; i < repeatCount; i++) {
      listOfLists.expand((e) => e).toList();
    }
    print('[expand: ${timer.elapsedMilliseconds}]');
  }

  {
    final timer = Stopwatch()..start();
    for (var i = 0; i < repeatCount; i++) {
      listOfLists.flattened.toList();
    }
    print('[flattened: ${timer.elapsedMilliseconds}]');
  }

  {
    final timer = Stopwatch()..start();
    for (var i = 0; i < repeatCount; i++) {
      listOfLists.flattened2.toList();
    }
    print('[flattened2: ${timer.elapsedMilliseconds}]');
  }
}

extension ListListExtensions<T> on List<List<T>> {
  Iterable<T> get flattened2 {
    return [
      for (final elements in this) ...elements,
    ];
  }
}

Change-Id: I0bf9dc0c8735fe62aab69cbce276254e2db110f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345202
Reviewed-by: Jacob Richman <jacobr@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2024-01-08 18:55:48 +00:00
..

analysis_server

A long-running process that provides analysis results to other tools.

The analysis server is designed to provide on-going analysis of one or more code bases as those code bases are changing.

Using the server

The analysis server is not intended to be used stand-alone, and therefore does not have a human-friendly user interface.

Clients (typically tools, such as an editor) are expected to run the analysis server in a separate process and communicate with it using a JSON protocol. The original protocol is specified in the file analysis_server/doc/api.html and Language Server Protocol support is documented in tool/lsp_spec/README.md.

Features and bugs

Please file feature requests and bugs at the issue tracker.