Changeset 41068 in webkit for trunk/JavaScriptCore
- Timestamp:
- Feb 18, 2009, 3:26:35 PM (16 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r41060 r41068 1 2009-02-18 David Levin <[email protected]> 2 3 Reviewed by Alexey Proskuryakov. 4 5 Bug 23974: Deque::Remove would be a useful method. 6 <https://bugs.webkit.org/show_bug.cgi?id=23974> 7 8 Add Deque::remove and DequeIteratorBase<T>::operator=. 9 10 Why was operator= added? Every concrete iterator (DequeIterator..DequeConstReverseIterator) 11 was calling DequeIteratorBase::assign(), which called Base::operator=(). Base::operator=() 12 was not implemented. This went unnoticed because the iterator copy code has been unused. 13 14 * wtf/Deque.h: 15 (WTF::Deque<T>::remove): 16 (WTF::DequeIteratorBase<T>::removeFromIteratorsList): 17 (WTF::DequeIteratorBase<T>::operator=): 18 (WTF::DequeIteratorBase<T>::~DequeIteratorBase): 19 1 20 2009-02-18 Gustavo Noronha Silva <[email protected]> 2 21 -
trunk/JavaScriptCore/wtf/Deque.h
r32234 r41068 1 1 /* 2 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without … … 76 77 template<typename U> void prepend(const U&); 77 78 void removeFirst(); 79 void remove(iterator&); 80 void remove(const_iterator&); 78 81 79 82 void clear(); … … 86 89 typedef DequeIteratorBase<T> IteratorBase; 87 90 91 void remove(size_t position); 88 92 void invalidateIterators(); 89 93 void destroyAll(); … … 125 129 private: 126 130 void addToIteratorsList(); 131 void removeFromIteratorsList(); 127 132 void checkValidity() const; 128 133 void checkValidity(const Base&) const; … … 448 453 } 449 454 455 template<typename T> 456 inline void Deque<T>::remove(iterator& it) 457 { 458 it.checkValidity(); 459 remove(it.m_index); 460 } 461 462 template<typename T> 463 inline void Deque<T>::remove(const_iterator& it) 464 { 465 it.checkValidity(); 466 remove(it.m_index); 467 } 468 469 template<typename T> 470 inline void Deque<T>::remove(size_t position) 471 { 472 if (position == m_end) 473 return; 474 475 checkValidity(); 476 invalidateIterators(); 477 478 T* buffer = m_buffer.buffer(); 479 TypeOperations::destruct(&buffer[position], &buffer[position + 1]); 480 481 // Find which segment of the circular buffer contained the remove element, and only move elements in that part. 482 if (position >= m_start) { 483 TypeOperations::moveOverlapping(buffer + m_start, buffer + position, buffer + m_start + 1); 484 m_start = (m_start + 1) % m_buffer.capacity(); 485 } else { 486 TypeOperations::moveOverlapping(buffer + position + 1, buffer + m_end, buffer + position); 487 m_end = (m_end - 1 + m_buffer.capacity()) % m_buffer.capacity(); 488 } 489 checkValidity(); 490 } 491 450 492 #ifdef NDEBUG 451 493 template<typename T> inline void DequeIteratorBase<T>::checkValidity() const { } 452 494 template<typename T> inline void DequeIteratorBase<T>::checkValidity(const DequeIteratorBase<T>&) const { } 453 495 template<typename T> inline void DequeIteratorBase<T>::addToIteratorsList() { } 496 template<typename T> inline void DequeIteratorBase<T>::removeFromIteratorsList() { } 454 497 #else 455 498 template<typename T> … … 481 524 m_previous = 0; 482 525 } 483 #endif 484 485 template<typename T> 486 inline DequeIteratorBase<T>::DequeIteratorBase() 487 : m_deque(0) 488 { 489 } 490 491 template<typename T> 492 inline DequeIteratorBase<T>::DequeIteratorBase(const Deque<T>* deque, size_t index) 493 : m_deque(const_cast<Deque<T>*>(deque)) 494 , m_index(index) 495 { 496 addToIteratorsList(); 497 checkValidity(); 498 } 499 500 template<typename T> 501 inline DequeIteratorBase<T>::DequeIteratorBase(const Base& other) 502 : m_deque(other.m_deque) 503 , m_index(other.m_index) 504 { 505 addToIteratorsList(); 506 checkValidity(); 507 } 508 509 template<typename T> 510 inline DequeIteratorBase<T>::~DequeIteratorBase() 511 { 512 #ifndef NDEBUG 513 // Delete iterator from doubly-linked list of iterators. 526 527 template<typename T> 528 void DequeIteratorBase<T>::removeFromIteratorsList() 529 { 514 530 if (!m_deque) { 515 531 ASSERT(!m_next); … … 529 545 } 530 546 } 531 m_deque = 0;532 547 m_next = 0; 533 548 m_previous = 0; 549 } 550 #endif 551 552 template<typename T> 553 inline DequeIteratorBase<T>::DequeIteratorBase() 554 : m_deque(0) 555 { 556 } 557 558 template<typename T> 559 inline DequeIteratorBase<T>::DequeIteratorBase(const Deque<T>* deque, size_t index) 560 : m_deque(const_cast<Deque<T>*>(deque)) 561 , m_index(index) 562 { 563 addToIteratorsList(); 564 checkValidity(); 565 } 566 567 template<typename T> 568 inline DequeIteratorBase<T>::DequeIteratorBase(const Base& other) 569 : m_deque(other.m_deque) 570 , m_index(other.m_index) 571 { 572 addToIteratorsList(); 573 checkValidity(); 574 } 575 576 template<typename T> 577 inline DequeIteratorBase<T>& DequeIteratorBase<T>::operator=(const Base& other) 578 { 579 checkValidity(); 580 other.checkValidity(); 581 removeFromIteratorsList(); 582 583 m_deque = other.m_deque; 584 m_index = other.m_index; 585 addToIteratorsList(); 586 checkValidity(); 587 return *this; 588 } 589 590 template<typename T> 591 inline DequeIteratorBase<T>::~DequeIteratorBase() 592 { 593 #ifndef NDEBUG 594 removeFromIteratorsList(); 595 m_deque = 0; 534 596 #endif 535 597 }
Note:
See TracChangeset
for help on using the changeset viewer.