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

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

Issue 807003004: Templatize visitor arguments for TraceTrait mark and trace methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebased Created 6 years 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
« no previous file with comments | « Source/platform/heap/Visitor.h ('k') | Source/wtf/HashTable.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 void removeFirst(); 105 void removeFirst();
106 void removeLast(); 106 void removeLast();
107 void remove(iterator&); 107 void remove(iterator&);
108 void remove(const_iterator&); 108 void remove(const_iterator&);
109 109
110 void clear(); 110 void clear();
111 111
112 template<typename Predicate> 112 template<typename Predicate>
113 iterator findIf(Predicate&); 113 iterator findIf(Predicate&);
114 114
115 void trace(typename Allocator::Visitor*); 115 template<typename VisitorDispatcher> void trace(VisitorDispatcher);
116 116
117 private: 117 private:
118 friend class DequeIteratorBase<T, inlineCapacity, Allocator>; 118 friend class DequeIteratorBase<T, inlineCapacity, Allocator>;
119 119
120 typedef VectorBuffer<T, inlineCapacity, Allocator> Buffer; 120 typedef VectorBuffer<T, inlineCapacity, Allocator> Buffer;
121 typedef VectorTypeOperations<T> TypeOperations; 121 typedef VectorTypeOperations<T> TypeOperations;
122 typedef DequeIteratorBase<T, inlineCapacity, Allocator> IteratorBase; 122 typedef DequeIteratorBase<T, inlineCapacity, Allocator> IteratorBase;
123 123
124 void remove(size_t position); 124 void remove(size_t position);
125 void destroyAll(); 125 void destroyAll();
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 { 513 {
514 ASSERT(m_index != m_deque->m_start); 514 ASSERT(m_index != m_deque->m_start);
515 if (!m_index) 515 if (!m_index)
516 return &m_deque->m_buffer.buffer()[m_deque->m_buffer.capacity() - 1] ; 516 return &m_deque->m_buffer.buffer()[m_deque->m_buffer.capacity() - 1] ;
517 return &m_deque->m_buffer.buffer()[m_index - 1]; 517 return &m_deque->m_buffer.buffer()[m_index - 1];
518 } 518 }
519 519
520 // This is only called if the allocator is a HeapAllocator. It is used when 520 // This is only called if the allocator is a HeapAllocator. It is used when
521 // visiting during a tracing GC. 521 // visiting during a tracing GC.
522 template<typename T, size_t inlineCapacity, typename Allocator> 522 template<typename T, size_t inlineCapacity, typename Allocator>
523 void Deque<T, inlineCapacity, Allocator>::trace(typename Allocator::Visitor* visitor) 523 template<typename VisitorDispatcher>
524 void Deque<T, inlineCapacity, Allocator>::trace(VisitorDispatcher visitor)
524 { 525 {
525 ASSERT(Allocator::isGarbageCollected); // Garbage collector must be enab led. 526 ASSERT(Allocator::isGarbageCollected); // Garbage collector must be enab led.
526 const T* bufferBegin = m_buffer.buffer(); 527 const T* bufferBegin = m_buffer.buffer();
527 const T* end = bufferBegin + m_end; 528 const T* end = bufferBegin + m_end;
528 if (ShouldBeTraced<VectorTraits<T> >::value) { 529 if (ShouldBeTraced<VectorTraits<T> >::value) {
529 if (m_start <= m_end) { 530 if (m_start <= m_end) {
530 for (const T* bufferEntry = bufferBegin + m_start; bufferEntry ! = end; bufferEntry++) 531 for (const T* bufferEntry = bufferBegin + m_start; bufferEntry ! = end; bufferEntry++)
531 Allocator::template trace<T, VectorTraits<T> >(visitor, *con st_cast<T*>(bufferEntry)); 532 Allocator::template trace<VisitorDispatcher, T, VectorTraits <T> >(visitor, *const_cast<T*>(bufferEntry));
532 } else { 533 } else {
533 for (const T* bufferEntry = bufferBegin; bufferEntry != end; buf ferEntry++) 534 for (const T* bufferEntry = bufferBegin; bufferEntry != end; buf ferEntry++)
534 Allocator::template trace<T, VectorTraits<T> >(visitor, *con st_cast<T*>(bufferEntry)); 535 Allocator::template trace<VisitorDispatcher, T, VectorTraits <T> >(visitor, *const_cast<T*>(bufferEntry));
535 const T* bufferEnd = m_buffer.buffer() + m_buffer.capacity(); 536 const T* bufferEnd = m_buffer.buffer() + m_buffer.capacity();
536 for (const T* bufferEntry = bufferBegin + m_start; bufferEntry ! = bufferEnd; bufferEntry++) 537 for (const T* bufferEntry = bufferBegin + m_start; bufferEntry ! = bufferEnd; bufferEntry++)
537 Allocator::template trace<T, VectorTraits<T> >(visitor, *con st_cast<T*>(bufferEntry)); 538 Allocator::template trace<VisitorDispatcher, T, VectorTraits <T> >(visitor, *const_cast<T*>(bufferEntry));
538 } 539 }
539 } 540 }
540 if (m_buffer.hasOutOfLineBuffer()) 541 if (m_buffer.hasOutOfLineBuffer())
541 Allocator::markNoTracing(visitor, m_buffer.buffer()); 542 Allocator::markNoTracing(visitor, m_buffer.buffer());
542 } 543 }
543 544
544 template<typename T, size_t inlineCapacity, typename Allocator> 545 template<typename T, size_t inlineCapacity, typename Allocator>
545 inline void swap(Deque<T, inlineCapacity, Allocator>& a, Deque<T, inlineCapa city, Allocator>& b) 546 inline void swap(Deque<T, inlineCapacity, Allocator>& a, Deque<T, inlineCapa city, Allocator>& b)
546 { 547 {
547 a.swap(b); 548 a.swap(b);
548 } 549 }
549 550
550 #if !ENABLE(OILPAN) 551 #if !ENABLE(OILPAN)
551 template<typename T, size_t N> 552 template<typename T, size_t N>
552 struct NeedsTracing<Deque<T, N> > { 553 struct NeedsTracing<Deque<T, N> > {
553 static const bool value = false; 554 static const bool value = false;
554 }; 555 };
555 #endif 556 #endif
556 557
557 } // namespace WTF 558 } // namespace WTF
558 559
559 using WTF::Deque; 560 using WTF::Deque;
560 561
561 #endif // WTF_Deque_h 562 #endif // WTF_Deque_h
OLDNEW
« no previous file with comments | « Source/platform/heap/Visitor.h ('k') | Source/wtf/HashTable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698