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

Side by Side Diff: Source/core/html/HTMLCollection.h

Issue 113653006: Remove complexity related to m_cachedElementsArrayOffset from LiveNodeListBase (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r ights reserved. 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r ights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 17 matching lines...) Expand all
28 #include "wtf/Forward.h" 28 #include "wtf/Forward.h"
29 #include "wtf/HashMap.h" 29 #include "wtf/HashMap.h"
30 #include "wtf/Vector.h" 30 #include "wtf/Vector.h"
31 31
32 namespace WebCore { 32 namespace WebCore {
33 33
34 class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection> , public LiveNodeListBase { 34 class HTMLCollection : public ScriptWrappable, public RefCounted<HTMLCollection> , public LiveNodeListBase {
35 public: 35 public:
36 static PassRefPtr<HTMLCollection> create(Node* base, CollectionType); 36 static PassRefPtr<HTMLCollection> create(Node* base, CollectionType);
37 virtual ~HTMLCollection(); 37 virtual ~HTMLCollection();
38 virtual void invalidateCache() const OVERRIDE;
38 39
39 // DOM API 40 // DOM API
40 virtual Node* namedItem(const AtomicString& name) const; 41 virtual Node* namedItem(const AtomicString& name) const;
41 42
42 // Non-DOM API 43 // Non-DOM API
43 void namedItems(const AtomicString& name, Vector<RefPtr<Node> >&) const; 44 void namedItems(const AtomicString& name, Vector<RefPtr<Node> >&) const;
44 bool isEmpty() const 45 bool isEmpty() const
45 { 46 {
46 if (isLengthCacheValid()) 47 if (isLengthCacheValid())
47 return !cachedLength(); 48 return !cachedLength();
48 if (isItemCacheValid()) 49 if (isItemCacheValid())
49 return !cachedItem(); 50 return !cachedItem();
50 return !item(0); 51 return !item(0);
51 } 52 }
52 bool hasExactlyOneItem() const 53 bool hasExactlyOneItem() const
53 { 54 {
54 if (isLengthCacheValid()) 55 if (isLengthCacheValid())
55 return cachedLength() == 1; 56 return cachedLength() == 1;
56 if (isItemCacheValid()) 57 if (isItemCacheValid())
57 return cachedItem() && !cachedItemOffset() && !item(1); 58 return cachedItem() && !cachedItemOffset() && !item(1);
58 return item(0) && !item(1); 59 return item(0) && !item(1);
59 } 60 }
60 61
61 virtual Element* virtualItemAfter(unsigned& offsetInArray, Element*) const; 62 virtual Element* virtualItemAfter(Element*) const;
62 63
63 Element* traverseFirstElement(unsigned& offsetInArray, ContainerNode& root) const; 64 Element* traverseFirstElement(ContainerNode& root) const;
64 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u nsigned& currentOffset, unsigned& offsetInArray, ContainerNode* root) const; 65 Element* traverseForwardToOffset(unsigned offset, Element& currentElement, u nsigned& currentOffset, ContainerNode* root) const;
65 66
66 protected: 67 protected:
67 HTMLCollection(Node* base, CollectionType, ItemAfterOverrideType); 68 HTMLCollection(Node* base, CollectionType, ItemAfterOverrideType);
68 69
69 virtual void updateNameCache() const; 70 virtual void updateNameCache() const;
70 71
71 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap; 72 typedef HashMap<StringImpl*, OwnPtr<Vector<Element*> > > NodeCacheMap;
72 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache .get(name.impl()); } 73 Vector<Element*>* idCache(const AtomicString& name) const { return m_idCache .get(name.impl()); }
73 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC ache.get(name.impl()); } 74 Vector<Element*>* nameCache(const AtomicString& name) const { return m_nameC ache.get(name.impl()); }
74 void appendIdCache(const AtomicString& name, Element* element) const { appen d(m_idCache, name, element); } 75 void appendIdCache(const AtomicString& name, Element* element) const { appen d(m_idCache, name, element); }
75 void appendNameCache(const AtomicString& name, Element* element) const { app end(m_nameCache, name, element); } 76 void appendNameCache(const AtomicString& name, Element* element) const { app end(m_nameCache, name, element); }
76 77
77 private: 78 private:
78 bool checkForNameMatch(Element*, bool checkName, const AtomicString& name) c onst; 79 bool checkForNameMatch(Element*, bool checkName, const AtomicString& name) c onst;
79 Element* traverseNextElement(unsigned& offsetInArray, Element& previous, Con tainerNode* root) const; 80 Element* traverseNextElement(Element& previous, ContainerNode* root) const;
80 81
81 static void append(NodeCacheMap&, const AtomicString&, Element*); 82 static void append(NodeCacheMap&, const AtomicString&, Element*);
83 void invalidateIdNameCacheMaps() const
84 {
85 m_idCache.clear();
86 m_nameCache.clear();
87 }
82 88
83 mutable NodeCacheMap m_idCache; 89 mutable NodeCacheMap m_idCache;
84 mutable NodeCacheMap m_nameCache; 90 mutable NodeCacheMap m_nameCache;
85 mutable unsigned m_cachedElementsArrayOffset;
86 91
87 friend class LiveNodeListBase; 92 friend class LiveNodeListBase;
88 }; 93 };
89 94
90 } // namespace 95 } // namespace
91 96
92 #endif 97 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698