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

Side by Side Diff: third_party/WebKit/Source/wtf/Deque.h

Issue 2579773002: Use WTF::Deque instead of std::queue in the blink scheduler (Closed)
Patch Set: Apply the fix Sami suggested Created 3 years, 11 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 /* 1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 127
128 template <typename U> 128 template <typename U>
129 void append(U&&); 129 void append(U&&);
130 template <typename U> 130 template <typename U>
131 void prepend(U&&); 131 void prepend(U&&);
132 void removeFirst(); 132 void removeFirst();
133 void removeLast(); 133 void removeLast();
134 void remove(iterator&); 134 void remove(iterator&);
135 void remove(const_iterator&); 135 void remove(const_iterator&);
136 136
137 // STL compatibility.
138 template <typename U>
139 void push_back(U&& u) {
140 append(std::forward<U>(u));
141 }
142 template <typename U>
143 void push_front(U&& u) {
144 prepend(std::forward<U>(u));
145 }
146 void pop_back() { removeLast(); }
147 void pop_front() { removeFirst(); }
148 bool empty() const { return isEmpty(); }
149 T& front() { return first(); }
150 const T& front() const { return first(); }
151 T& back() { return last(); }
152 const T& back() const { return last(); }
153 template <typename... Args>
154 void emplace_back(Args&&...);
155 template <typename... Args>
156 void emplace_front(Args&&...);
haraken 2017/01/11 15:20:35 pilgrim@: Does this align with your renaming plan?
alex clarke (OOO till 29th) 2017/01/11 15:29:53 It might make sense to (in a follow up patch) rena
157
137 void clear(); 158 void clear();
138 159
139 template <typename VisitorDispatcher> 160 template <typename VisitorDispatcher>
140 void trace(VisitorDispatcher); 161 void trace(VisitorDispatcher);
141 162
142 static_assert(!std::is_polymorphic<T>::value || 163 static_assert(!std::is_polymorphic<T>::value ||
143 !VectorTraits<T>::canInitializeWithMemset, 164 !VectorTraits<T>::canInitializeWithMemset,
144 "Cannot initialize with memset if there is a vtable"); 165 "Cannot initialize with memset if there is a vtable");
145 static_assert(Allocator::isGarbageCollected || 166 static_assert(Allocator::isGarbageCollected ||
146 !AllowsOnlyPlacementNew<T>::value || 167 !AllowsOnlyPlacementNew<T>::value ||
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 inline T Deque<T, inlineCapacity, Allocator>::takeLast() { 499 inline T Deque<T, inlineCapacity, Allocator>::takeLast() {
479 T oldLast = std::move(last()); 500 T oldLast = std::move(last());
480 removeLast(); 501 removeLast();
481 return oldLast; 502 return oldLast;
482 } 503 }
483 504
484 template <typename T, size_t inlineCapacity, typename Allocator> 505 template <typename T, size_t inlineCapacity, typename Allocator>
485 template <typename U> 506 template <typename U>
486 inline void Deque<T, inlineCapacity, Allocator>::append(U&& value) { 507 inline void Deque<T, inlineCapacity, Allocator>::append(U&& value) {
487 expandCapacityIfNeeded(); 508 expandCapacityIfNeeded();
488 new (NotNull, &m_buffer.buffer()[m_end]) T(std::forward<U>(value)); 509 T* newElement = &m_buffer.buffer()[m_end];
489 if (m_end == m_buffer.capacity() - 1) 510 if (m_end == m_buffer.capacity() - 1)
490 m_end = 0; 511 m_end = 0;
491 else 512 else
492 ++m_end; 513 ++m_end;
514 new (NotNull, newElement) T(std::forward<U>(value));
493 } 515 }
494 516
495 template <typename T, size_t inlineCapacity, typename Allocator> 517 template <typename T, size_t inlineCapacity, typename Allocator>
496 template <typename U> 518 template <typename U>
497 inline void Deque<T, inlineCapacity, Allocator>::prepend(U&& value) { 519 inline void Deque<T, inlineCapacity, Allocator>::prepend(U&& value) {
498 expandCapacityIfNeeded(); 520 expandCapacityIfNeeded();
499 if (!m_start) 521 if (!m_start)
500 m_start = m_buffer.capacity() - 1; 522 m_start = m_buffer.capacity() - 1;
501 else 523 else
502 --m_start; 524 --m_start;
503 new (NotNull, &m_buffer.buffer()[m_start]) T(std::forward<U>(value)); 525 new (NotNull, &m_buffer.buffer()[m_start]) T(std::forward<U>(value));
504 } 526 }
505 527
506 template <typename T, size_t inlineCapacity, typename Allocator> 528 template <typename T, size_t inlineCapacity, typename Allocator>
529 template <typename... Args>
530 inline void Deque<T, inlineCapacity, Allocator>::emplace_back(Args&&... args) {
531 expandCapacityIfNeeded();
532 T* newElement = &m_buffer.buffer()[m_end];
533 if (m_end == m_buffer.capacity() - 1)
534 m_end = 0;
535 else
536 ++m_end;
537 new (NotNull, newElement) T(std::forward<Args>(args)...);
538 }
539
540 template <typename T, size_t inlineCapacity, typename Allocator>
541 template <typename... Args>
542 inline void Deque<T, inlineCapacity, Allocator>::emplace_front(Args&&... args) {
543 expandCapacityIfNeeded();
544 if (!m_start)
545 m_start = m_buffer.capacity() - 1;
546 else
547 --m_start;
548 new (NotNull, &m_buffer.buffer()[m_start]) T(std::forward<Args>(args)...);
549 }
haraken 2017/01/11 15:20:35 Can we share these implementations with append/pre
alex clarke (OOO till 29th) 2017/01/11 15:29:53 Do you mean add emplace_append and emplace_prepend
haraken 2017/01/11 15:45:19 Ah, sorry. Ignore my comment :)
550
551 template <typename T, size_t inlineCapacity, typename Allocator>
507 inline void Deque<T, inlineCapacity, Allocator>::removeFirst() { 552 inline void Deque<T, inlineCapacity, Allocator>::removeFirst() {
508 DCHECK(!isEmpty()); 553 DCHECK(!isEmpty());
509 TypeOperations::destruct(&m_buffer.buffer()[m_start], 554 TypeOperations::destruct(&m_buffer.buffer()[m_start],
510 &m_buffer.buffer()[m_start + 1]); 555 &m_buffer.buffer()[m_start + 1]);
511 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_start], 556 m_buffer.clearUnusedSlots(&m_buffer.buffer()[m_start],
512 &m_buffer.buffer()[m_start + 1]); 557 &m_buffer.buffer()[m_start + 1]);
513 if (m_start == m_buffer.capacity() - 1) 558 if (m_start == m_buffer.capacity() - 1)
514 m_start = 0; 559 m_start = 0;
515 else 560 else
516 ++m_start; 561 ++m_start;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 inline void swap(Deque<T, inlineCapacity, Allocator>& a, 711 inline void swap(Deque<T, inlineCapacity, Allocator>& a,
667 Deque<T, inlineCapacity, Allocator>& b) { 712 Deque<T, inlineCapacity, Allocator>& b) {
668 a.swap(b); 713 a.swap(b);
669 } 714 }
670 715
671 } // namespace WTF 716 } // namespace WTF
672 717
673 using WTF::Deque; 718 using WTF::Deque;
674 719
675 #endif // WTF_Deque_h 720 #endif // WTF_Deque_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/scheduler/base/work_queue_unittest.cc ('k') | third_party/WebKit/Source/wtf/DequeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698