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; |
+} |