Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1056)

Unified Diff: pkg/analysis_server/lib/src/collections.dart

Issue 2914383002: Expose the exceptions info in the diagnostics page. (Closed)
Patch Set: review comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/collections.dart
diff --git a/pkg/analysis_server/lib/src/collections.dart b/pkg/analysis_server/lib/src/collections.dart
index e89350e41d622f650f9965780142c4a6a078c616..aa635d37361c288c1e2a599f28e4bbcec753c03f 100644
--- a/pkg/analysis_server/lib/src/collections.dart
+++ b/pkg/analysis_server/lib/src/collections.dart
@@ -45,3 +45,27 @@ class Pair<E, F> {
String toString() => '($first, $last)';
}
+
+/**
+ * A container that remembers the last `n` items added to it.
+ *
+ * It will never grow larger than [capacity]. It's a LIFO queue - the last item
+ * added will be the first one returned from [items].
+ */
+class RecentBuffer<T> {
+ final int capacity;
+
+ List<T> _buffer = [];
+
+ RecentBuffer(this.capacity);
+
+ void add(T item) {
+ _buffer.add(item);
+
+ if (_buffer.length > capacity) {
+ _buffer.removeAt(0);
+ }
+ }
+
+ Iterable<T> get items => _buffer.reversed;
+}

Powered by Google App Engine
This is Rietveld 408576698