Changeset 35425 in webkit for trunk/JavaScriptCore/wtf/Vector.h


Ignore:
Timestamp:
Jul 29, 2008, 11:51:26 AM (17 years ago)
Author:
Adam Roben
Message:

Change Vector::find to return an index instead of an iterator

Indices are more natural than iterators when working with Vector.

Reviewed by John Sullivan.

  • wtf/Vector.h: (WTF::Vector::find): Changed to iterate the Vector manually and return the index of the found item, rather than an iterator. When the item could not be found, we return WTF::notFound.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/Vector.h

    r35269 r35425  
    3737    using std::max;
    3838   
     39    const size_t notFound = static_cast<size_t>(-1);
     40
    3941    template <bool needsDestruction, typename T>
    4042    class VectorDestructor;
     
    461463        const T& last() const { return at(size() - 1); }
    462464
    463         template<typename U> iterator find(const U& value) { return std::find(begin(), end(), value); }
    464         template<typename U> const_iterator find(const U& value) const { return std::find(begin(), end(), value); }
     465        template<typename U> size_t find(const U&) const;
    465466
    466467        void shrink(size_t size);
     
    586587
    587588        return *this;
     589    }
     590
     591    template<typename T, size_t inlineCapacity>
     592    template<typename U>
     593    size_t Vector<T, inlineCapacity>::find(const U& value) const
     594    {
     595        for (size_t i = 0; i < size(); ++i) {
     596            if (at(i) == value)
     597                return i;
     598        }
     599        return notFound;
    588600    }
    589601
Note: See TracChangeset for help on using the changeset viewer.