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


Ignore:
Timestamp:
Jul 7, 2010, 2:21:08 PM (15 years ago)
Author:
[email protected]
Message:

2010-07-07 Adam Barth <[email protected]>

Reviewed by Sam Weinig.

Add reverseFind to Vector and deploy in HTML5 parser
https://bugs.webkit.org/show_bug.cgi?id=41778

This method seems generally useful. I'm slightly surprised we don't
have it already.

  • wtf/Vector.h: (WTF::::reverseFind):

2010-07-07 Adam Barth <[email protected]>

Reviewed by Sam Weinig.

Add reverseFind to Vector and deploy in HTML5 parser
https://bugs.webkit.org/show_bug.cgi?id=41778

This patch moves reverseFind from begin an
HTMLFormattingElementList-specific concept to begin a general Vector
concept. Also, instead of using Entry as the type for operator==, we
now use elements directly. The old code compiled because the Entry
constructor wasn't explicit, which means we were churning refs on every
comparison!

  • html/HTMLFormattingElementList.cpp: (WebCore::HTMLFormattingElementList::find): (WebCore::HTMLFormattingElementList::bookmarkFor): (WebCore::HTMLFormattingElementList::insertAt): (WebCore::HTMLFormattingElementList::remove):
  • html/HTMLFormattingElementList.h: (WebCore::HTMLFormattingElementList::Entry::operator==): (WebCore::HTMLFormattingElementList::Entry::operator!=):
File:
1 edited

Legend:

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

    r61475 r62697  
    558558
    559559        template<typename U> size_t find(const U&) const;
     560        template<typename U> size_t reverseFind(const U&) const;
    560561
    561562        void shrink(size_t size);
     
    740741            if (at(i) == value)
    741742                return i;
     743        }
     744        return notFound;
     745    }
     746
     747    template<typename T, size_t inlineCapacity>
     748    template<typename U>
     749    size_t Vector<T, inlineCapacity>::reverseFind(const U& value) const
     750    {
     751        for (size_t i = 1; i <= size(); ++i) {
     752            const size_t index = size() - i;
     753            if (at(index) == value)
     754                return index;
    742755        }
    743756        return notFound;
Note: See TracChangeset for help on using the changeset viewer.