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

Unified Diff: sdk/lib/collection/queue.dart

Issue 660373002: Add a QueueList class to the collection package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 2 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: sdk/lib/collection/queue.dart
diff --git a/sdk/lib/collection/queue.dart b/sdk/lib/collection/queue.dart
index 72c4e959459752fea930646827888f70089d38cd..9e8580d6d18751a8b48ea7c9a2d83abeee6e8fe3 100644
--- a/sdk/lib/collection/queue.dart
+++ b/sdk/lib/collection/queue.dart
@@ -587,7 +587,7 @@ class ListQueue<E> extends IterableBase<E> implements Queue<E> {
*/
static int _nextPowerOf2(int number) {
assert(number > 0);
- number = (number << 2) - 1;
+ number = (number << 1) - 1;
for(;;) {
int nextNumber = number & (number - 1);
if (nextNumber == 0) return number;
@@ -678,6 +678,10 @@ class ListQueue<E> extends IterableBase<E> implements Queue<E> {
/** Grows the table even if it is not full. */
void _preGrow(int newElementCount) {
assert(newElementCount >= length);
+
+ // Add some extra room to ensure that there's room for more elements after
+ // expansion.
+ newElementCount += newElementCount >> 1;
int newCapacity = _nextPowerOf2(newElementCount);
List<E> newTable = new List<E>(newCapacity);
_tail = _writeToList(newTable);
« pkg/collection/lib/src/queue_list.dart ('K') | « pkg/collection/test/queue_list_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698