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

Side by Side Diff: pkg/analysis_server/lib/src/operation/operation_queue.dart

Issue 1327173002: Make NavigationOperation a MergeableOperation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library operation.queue; 5 library operation.queue;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analysis_server/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/operation/operation.dart'; 10 import 'package:analysis_server/src/operation/operation.dart';
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 33
34 /** 34 /**
35 * Adds the given operation to this queue. The exact position in the queue 35 * Adds the given operation to this queue. The exact position in the queue
36 * depends on the priority of the given operation relative to the priorities 36 * depends on the priority of the given operation relative to the priorities
37 * of the other operations in the queue. 37 * of the other operations in the queue.
38 */ 38 */
39 void add(ServerOperation operation) { 39 void add(ServerOperation operation) {
40 int queueIndex = operation.priority.ordinal; 40 int queueIndex = operation.priority.ordinal;
41 Queue<ServerOperation> queue = _queues[queueIndex]; 41 Queue<ServerOperation> queue = _queues[queueIndex];
42 // try to merge into an existing operation
43 for (ServerOperation existingOperation in queue) {
44 if (existingOperation is MergeableOperation &&
45 existingOperation.merge(operation)) {
46 return;
47 }
48 }
49 // add it
42 queue.addLast(operation); 50 queue.addLast(operation);
43 } 51 }
44 52
45 /** 53 /**
46 * Removes all elements in the queue. 54 * Removes all elements in the queue.
47 */ 55 */
48 void clear() { 56 void clear() {
49 for (Queue<ServerOperation> queue in _queues) { 57 for (Queue<ServerOperation> queue in _queues) {
50 queue.clear(); 58 queue.clear();
51 } 59 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 120 }
113 } 121 }
114 return null; 122 return null;
115 } 123 }
116 124
117 /** 125 /**
118 * Returns an operation that satisfies the given [test] or `null`. 126 * Returns an operation that satisfies the given [test] or `null`.
119 */ 127 */
120 ServerOperation takeIf(bool test(ServerOperation operation)) { 128 ServerOperation takeIf(bool test(ServerOperation operation)) {
121 for (Queue<ServerOperation> queue in _queues) { 129 for (Queue<ServerOperation> queue in _queues) {
122 for (var operation in queue) { 130 for (ServerOperation operation in queue) {
123 if (test(operation)) { 131 if (test(operation)) {
124 queue.remove(operation); 132 queue.remove(operation);
125 return operation; 133 return operation;
126 } 134 }
127 } 135 }
128 } 136 }
129 return null; 137 return null;
130 } 138 }
131 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698